├── css ├── my.less ├── images │ ├── ui-icons_222222_256x240.png │ ├── ui-icons_228ef1_256x240.png │ ├── ui-icons_ef8c08_256x240.png │ ├── ui-icons_ffd27a_256x240.png │ ├── ui-icons_ffffff_256x240.png │ ├── ui-bg_flat_10_000000_40x100.png │ ├── ui-bg_glass_100_f6f6f6_1x400.png │ ├── ui-bg_glass_100_fdf5ce_1x400.png │ ├── ui-bg_glass_65_ffffff_1x400.png │ ├── ui-bg_gloss-wave_35_f6a828_500x100.png │ ├── ui-bg_diagonals-thick_18_b81900_40x40.png │ ├── ui-bg_diagonals-thick_20_666666_40x40.png │ ├── ui-bg_highlight-soft_100_eeeeee_1x100.png │ └── ui-bg_highlight-soft_75_ffe45c_1x100.png ├── style.css ├── bootstrap-responsive.min.css ├── bootstrap-responsive.css └── jquery-ui-1.8.21.custom.css ├── scripts ├── docs.tar.gz ├── suggest.tar.gz ├── suggest │ ├── README │ └── suggest.php └── sphinx.conf ├── img ├── glyphicons-halflings.png └── glyphicons-halflings-white.png ├── common.php ├── ajax_suggest.php ├── ajax_suggest_excerpts.php ├── template ├── footer_excerpts.php ├── footer.php ├── header.php └── paginator.php ├── README.md ├── index.php ├── functions.php ├── suggestcompleteexcerpts.php ├── qsuggest.php ├── suggestcomplete.php └── js ├── bootstrap-typeahead.js ├── bootstrap.min.js ├── less.min.js └── less-1.3.0.min.js /css/my.less: -------------------------------------------------------------------------------- 1 | @navbarBackground : @blue 2 | -------------------------------------------------------------------------------- /scripts/docs.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/scripts/docs.tar.gz -------------------------------------------------------------------------------- /scripts/suggest.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/scripts/suggest.tar.gz -------------------------------------------------------------------------------- /img/glyphicons-halflings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/img/glyphicons-halflings.png -------------------------------------------------------------------------------- /img/glyphicons-halflings-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/img/glyphicons-halflings-white.png -------------------------------------------------------------------------------- /css/images/ui-icons_222222_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-icons_222222_256x240.png -------------------------------------------------------------------------------- /css/images/ui-icons_228ef1_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-icons_228ef1_256x240.png -------------------------------------------------------------------------------- /css/images/ui-icons_ef8c08_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-icons_ef8c08_256x240.png -------------------------------------------------------------------------------- /css/images/ui-icons_ffd27a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-icons_ffd27a_256x240.png -------------------------------------------------------------------------------- /css/images/ui-icons_ffffff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-icons_ffffff_256x240.png -------------------------------------------------------------------------------- /css/images/ui-bg_flat_10_000000_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-bg_flat_10_000000_40x100.png -------------------------------------------------------------------------------- /css/images/ui-bg_glass_100_f6f6f6_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-bg_glass_100_f6f6f6_1x400.png -------------------------------------------------------------------------------- /css/images/ui-bg_glass_100_fdf5ce_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-bg_glass_100_fdf5ce_1x400.png -------------------------------------------------------------------------------- /css/images/ui-bg_glass_65_ffffff_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-bg_glass_65_ffffff_1x400.png -------------------------------------------------------------------------------- /css/images/ui-bg_gloss-wave_35_f6a828_500x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-bg_gloss-wave_35_f6a828_500x100.png -------------------------------------------------------------------------------- /css/images/ui-bg_diagonals-thick_18_b81900_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-bg_diagonals-thick_18_b81900_40x40.png -------------------------------------------------------------------------------- /css/images/ui-bg_diagonals-thick_20_666666_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-bg_diagonals-thick_20_666666_40x40.png -------------------------------------------------------------------------------- /css/images/ui-bg_highlight-soft_100_eeeeee_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-bg_highlight-soft_100_eeeeee_1x100.png -------------------------------------------------------------------------------- /css/images/ui-bg_highlight-soft_75_ffe45c_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriannuta/SphinxAutocompleteExample/HEAD/css/images/ui-bg_highlight-soft_75_ffe45c_1x100.png -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | .navbar-inner { 2 | background-color: #428ddf; 3 | background-image: -moz-linear-gradient(center top , #428ddf, #428ddf); 4 | } 5 | 6 | .navbar .brand { 7 | color: #ffffff 8 | } 9 | 10 | .navbar .nav .active > a, .navbar .nav .active > a:hover { 11 | background-color: #155BA9; 12 | } 13 | .ui-widget-content 14 | { 15 | background:#FFFFFF; 16 | } -------------------------------------------------------------------------------- /common.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/suggest/README: -------------------------------------------------------------------------------- 1 | Suggestions sample 2 | ------------------- 3 | 4 | 0) What's this. This sample shows how to implement simple keyword 5 | correction suggestions (ie. "did you mean") using Sphinx. 6 | 7 | 1) Requirements. You will need Sphinx, MySQL, and PHP CLI. 8 | 9 | 2) Quickstart. (Skip first indexer command to use bundled sample.) 10 | 11 | indexer YOURINDEX --config YOURCONFIG.CONF --buildstops dict.txt 100000 --buildfreqs 12 | cat dict.txt | php suggest.php --builddict > dict.sql 13 | mysql -u root test < dict.sql 14 | indexer --config suggest.conf --all 15 | searchd --config suggest.conf 16 | php suggest.php --query sphynx 17 | 18 | --eof-- 19 | -------------------------------------------------------------------------------- /ajax_suggest.php: -------------------------------------------------------------------------------- 1 | prepare("SELECT * FROM $indexes WHERE MATCH(:match) LIMIT 0,10 OPTION ranker=sph04"); 9 | 10 | 11 | $aq = explode(' ',$q); 12 | if(strlen($aq[count($aq)-1])<3){ 13 | $query = $q; 14 | }else{ 15 | $query = $q.'*'; 16 | } 17 | $stmt->bindValue(':match', $query,PDO::PARAM_STR); 18 | $stmt->execute(); 19 | 20 | foreach($stmt->fetchAll() as $r){ 21 | $arr[] = array('id' => utf8_encode($r['title']),'label' =>utf8_encode( $r['title'])); 22 | } 23 | 24 | echo json_encode($arr); 25 | exit(); 26 | -------------------------------------------------------------------------------- /ajax_suggest_excerpts.php: -------------------------------------------------------------------------------- 1 | prepare("SELECT * FROM $indexes WHERE MATCH(:match) LIMIT 0,10 OPTION ranker=sph04"); 9 | 10 | 11 | $aq = explode(' ',$q); 12 | if(strlen($aq[count($aq)-1])<3){ 13 | $query = $q; 14 | }else{ 15 | $query = $q.'*'; 16 | } 17 | $stmt->bindValue(':match', $query,PDO::PARAM_STR); 18 | $stmt->execute(); 19 | 20 | $docs = array(); 21 | $title = ""; 22 | $stmsnp = $ln_sph->prepare("CALL SNIPPETS(:doc,'simplecomplete',:query)"); 23 | $stmsnp->bindValue(':query',$query,PDO::PARAM_STR); 24 | $stmsnp->bindParam(':doc',$title,PDO::PARAM_STR); 25 | 26 | foreach($stmt->fetchAll() as $r){ 27 | $title = $r['title']; 28 | $stmsnp->execute(); 29 | $r = $stmsnp->fetch(); 30 | $arr[] = array('id' => utf8_encode($r['snippet']),'label' =>utf8_encode( $r['snippet'])); 31 | } 32 | 33 | 34 | echo json_encode($arr); 35 | exit(); 36 | -------------------------------------------------------------------------------- /template/footer_excerpts.php: -------------------------------------------------------------------------------- 1 |
2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /template/footer.php: -------------------------------------------------------------------------------- 1 |
2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /template/header.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <?=$title?> 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 36 |
37 |
38 |
39 |
40 |
45 |
46 |
47 | -------------------------------------------------------------------------------- /template/paginator.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | =2) { 6 | $previous = $current -1; 7 | } 8 | if($current+1<=$pageCount) { 9 | $next = $current+1; 10 | } 11 | $range = 3; 12 | $first = 0; 13 | $last = $pageCount; 14 | ?> 15 |
16 | 17 | 18 | 19 | | 20 | 21 | | 22 | 23 | 24 | 25 | 26 | | 27 | 28 | | 29 | 30 | 31 | 32 | 33 | 0 && $page <=$pageCount): ?> 34 | 35 | 36 | 37 | | 38 | 39 | | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | | 48 | 49 | | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
61 | -------------------------------------------------------------------------------- /scripts/sphinx.conf: -------------------------------------------------------------------------------- 1 | source suggest 2 | { 3 | type = mysql 4 | sql_host = localhost 5 | sql_user = MYUSER 6 | sql_pass = MYPASS 7 | sql_db = MYDB 8 | sql_port = 3306 9 | 10 | sql_query_pre = SET NAMES utf8 11 | sql_query = SELECT id, trigrams, freq, LENGTH(keyword) AS len, keyword FROM suggest 12 | sql_attr_uint = freq 13 | sql_attr_uint = len 14 | sql_attr_string = keyword 15 | } 16 | 17 | index suggest 18 | { 19 | source = suggest 20 | path = /PATH/TO/suggest_idx 21 | docinfo = extern 22 | charset_type = utf-8 23 | } 24 | 25 | source simplecomplete 26 | { 27 | type = mysql 28 | sql_host = localhost 29 | sql_user = MYUSER 30 | sql_pass = MYPASS 31 | sql_db = MYDB 32 | sql_port = 3306 33 | 34 | sql_query = select id,title from docs 35 | sql_field_string = title 36 | } 37 | 38 | index simplecomplete 39 | { 40 | source = simplecomplete 41 | path = /PATH/TO/simplecomplete_idx 42 | docinfo = extern 43 | charset_type = utf-8 44 | min_word_len = 3 45 | enable_star = 1 46 | min_prefix_len = 3 47 | } 48 | source simplecompletefull 49 | { 50 | type = mysql 51 | sql_host = localhost 52 | sql_user = MYUSER 53 | sql_pass = MYPASS 54 | sql_db = MYDB 55 | sql_port = 3306 56 | 57 | sql_query_pre = SET NAMES utf8 58 | sql_query = select id,title,content from docs 59 | } 60 | 61 | index simplecompletefull 62 | { 63 | source = simplecompletefull 64 | path = /PATH/TO/simplecompletefull_idx 65 | docinfo = extern 66 | charset_type = utf-8 67 | min_word_len = 3 68 | #min_infix_len = 3 # for CALL SUGGEST 69 | } 70 | 71 | indexer 72 | { 73 | mem_limit = 64M 74 | } 75 | 76 | searchd 77 | { 78 | listen = 9312 79 | listen = 9306:mysql41 80 | log = /PATH/TO/searchd.log 81 | query_log = /PATH/TO/query.log 82 | query_log_format = sphinxql 83 | read_timeout = 5 84 | max_children = 30 85 | pid_file = /PATH/TO/searchd.pid 86 | max_matches = 1000 87 | seamless_rotate = 1 88 | preopen_indexes = 1 89 | unlink_old = 1 90 | workers = threads 91 | } 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SphinxAutocompleteExample 2 | ========================= 3 | 4 | These samples illustrate autocomplete and type suggestion using Manticore/Sphinx search. 5 | Querying is made via SphinxQL using PDO driver. 6 | The sample data included contains a version of Sphinx documentation. 7 | The samples are featured on [this Sphinx blog post] (http://sphinxsearch.com/blog/2013/05/21/simple-autocomplete-and-correction-suggestion/). 8 | 9 | Requirements : 10 | ------------------------------------------- 11 | LAMP 12 | Manticore or Sphinx search 13 | PHP with PDO mysql 14 | 15 | Installation : 16 | ------------------------------------------- 17 | Edit `scripts/sphinx.conf` for setting proper paths and db credentials 18 | Import the sample tables in your database. 19 | Untar first the two archieves in `scripts` folder: 20 | 21 | $ tar -xzvf suggest.tar.gz 22 | $ tar -xzvf docs.tar.gz 23 | $ mysql < suggest.sql 24 | $ mysql < docs.sql 25 | Alternative you can build the suggest table by following instructions in `scripts/suggest/README` 26 | 27 | The samples use 3 indexes : `simplecompletefull` for doing the actual search, `simplecomplete` for autocomplete and `suggest` for suggestions. 28 | `simpletecompletefull` can be used for autocomplete as well, if the search for completion is made only on title ( `@title $query` ). 29 | Index the 3 indexes: 30 | 31 | $ indexer -c /path/to/sphinx.conf --all 32 | 33 | Start a new Manticore/Sphinx server using sphinx.conf from `scripts` folder or import the indexes if you already have a running Sphinx server. 34 | 35 | $ searchd -c /path/to/sphinx.conf 36 | In case you start a new Manticore/Sphinx server, be sure to change the ports in **sphinx.conf** and **common.php**. 37 | In **common.php** edit the database credentials. For Sphinx 2.1.1 or greater/Manticore or trunk version, set constant `SPHINX_20` to **false**. 38 | Autocomplete starts after typing 3 characters. To change this you need to edit in **sphinx.conf** `min_prefix_len` and `min_word_len` and in **footer.php** and **footer_excerpts.php** the `minLength` ( which trigger firing the ajax call). 39 | 40 | Live demo with Sphinx : 41 | ------------------------------------------- 42 | http://demos.sphinxsearch.com/SphinxAutocompleteExample/ 43 | License: 44 | ------------------------------------------- 45 | Sphinx Samples is free software, and is released under the terms of the GPL version 2 or (at your option) any later version. 46 | Manticore website : https://manticoresearch.com/ 47 | Manticore repository : https://github.com/manticoresoftware/manticore 48 | Sphinx website : http://sphinxsearch.com/ 49 | Sphinx read-only repository :https://github.com/sphinxsearch/sphinx 50 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | prepare("SELECT * FROM $indexes WHERE MATCH(:match) LIMIT $start,$offset OPTION ranker=sph04,field_weights=(title=100,content=1)"); 19 | $stmt->bindValue(':match', $query,PDO::PARAM_STR); 20 | $stmt->execute(); 21 | $rows = $stmt->fetchAll(); 22 | $meta = $ln_sph->query("SHOW META")->fetchAll(); 23 | foreach($meta as $m) { 24 | $meta_map[$m['Variable_name']] = $m['Value']; 25 | } 26 | $total_found = $meta_map['total_found']; 27 | $total = $meta_map['total']; 28 | $ids = array(); 29 | $tmpdocs = array(); 30 | if (count($rows)> 0) { 31 | foreach ($rows as $v) { 32 | $ids[] = $v['id']; 33 | } 34 | //grab the raw content from database 35 | $q = "SELECT id,title ,content FROM docs WHERE id IN (" . implode(',', $ids) . ")"; 36 | 37 | foreach($ln->query($q) as $row) 38 | $tmpdocs[$row['id']] = array('title' => $row['title'], 'content' => $row[content]); 39 | //it's important to keep the order returned by Sphinx 40 | foreach ($ids as $id) { 41 | $docs[] = $tmpdocs[$id]; 42 | } 43 | } 44 | } 45 | ?> 46 | 50 |
51 | 61 |
62 |

Simple autocomplete on title

63 |
64 |
65 |
66 |

Autocomplete is made using star on a titles index (with infixes).

67 |

Start typing in the field below

68 | 75 |
76 |
77 |

78 | 79 | Total found: 80 | 81 |

82 |
83 | 0): ?> 84 |
85 | 86 |
87 |
88 |

89 | 90 |

91 |

92 | 93 |

94 | 95 |
96 |
97 | 98 |
99 | 100 |

Nothing found!

101 | 102 |
103 | 107 | -------------------------------------------------------------------------------- /functions.php: -------------------------------------------------------------------------------- 1 | prepare("CALL SUGGEST(:keyword,'$index')"); 14 | $stmt->bindValue(':keyword', $keyword,PDO::PARAM_STR); 15 | $stmt->execute(); 16 | $row = $stmt->fetch(PDO::FETCH_ASSOC); 17 | return $row['suggest']; 18 | } 19 | 20 | function MakeMultiQSuggest($words,$query,$index,$ln_sph) 21 | { 22 | $suggested = array(); 23 | $llimf = 0; 24 | $i = 0; 25 | foreach ($words as $key => $word) { 26 | if ($word['docs'] != 0) 27 | $llimf +=$word['docs'];$i++; 28 | } 29 | $llimf = $llimf / ($i * $i); 30 | foreach ($words as $key => $word) { 31 | if ($word['docs'] == 0 | $word['docs'] < $llimf) { 32 | $mis[] = $word['keyword']; 33 | } 34 | } 35 | if (count($mis) > 0) { 36 | foreach ($mis as $m) { 37 | $re = MakeQSuggest($m,$index, $ln_sph); 38 | if ($re) { 39 | if($m!=$re) 40 | $suggested[$m] = $re; 41 | } 42 | } 43 | if(count($words) ==1 && empty($suggested)) { 44 | return false; 45 | } 46 | $phrase = explode(' ', $query); 47 | foreach ($phrase as $k => $word) { 48 | if (isset($suggested[strtolower($word)])) 49 | $phrase[$k] = $suggested[strtolower($word)]; 50 | } 51 | $phrase = implode(' ', $phrase); 52 | return $phrase; 53 | }else{ 54 | return false; 55 | } 56 | } 57 | function MakeSuggestion($keyword,$ln) 58 | { 59 | $trigrams = BuildTrigrams($keyword); 60 | $query = "\"$trigrams\"/1"; 61 | $len = strlen($keyword); 62 | 63 | $delta = LENGTH_THRESHOLD; 64 | $weight = 'weight()'; 65 | if(SPHINX_20 == true) { 66 | $weight ='@weight'; 67 | } 68 | $stmt = $ln->prepare("SELECT *, $weight as w, w+:delta-ABS(len-:len) as myrank FROM suggest WHERE MATCH(:match) AND len BETWEEN :lowlen AND :highlen 69 | ORDER BY myrank DESC, freq DESC 70 | LIMIT 0,:topcount OPTION ranker=wordcount"); 71 | 72 | $stmt->bindValue(':match', $query, PDO::PARAM_STR); 73 | $stmt->bindValue(':len', $len, PDO::PARAM_INT); 74 | $stmt->bindValue(':delta', $delta, PDO::PARAM_INT); 75 | $stmt->bindValue(':lowlen', $len - $delta, PDO::PARAM_INT); 76 | $stmt->bindValue(':highlen', $len + $delta, PDO::PARAM_INT); 77 | $stmt->bindValue(':topcount',TOP_COUNT, PDO::PARAM_INT); 78 | $stmt->execute(); 79 | 80 | 81 | if (!$rows = $stmt->fetchAll()) 82 | return false; 83 | // further restrict trigram matches with a sane Levenshtein distance limit 84 | foreach ($rows as $match) { 85 | $suggested = $match["keyword"]; 86 | if (levenshtein($keyword, $suggested) <= LEVENSHTEIN_THRESHOLD) 87 | return $suggested; 88 | } 89 | 90 | return $keyword; 91 | } 92 | 93 | function MakePhaseSuggestion($words,$query,$ln_sph) 94 | { 95 | $suggested = array(); 96 | $llimf = 0; 97 | $i = 0; 98 | foreach ($words as $key => $word) { 99 | if ($word['docs'] != 0) 100 | $llimf +=$word['docs'];$i++; 101 | } 102 | $llimf = $llimf / ($i * $i); 103 | foreach ($words as $key => $word) { 104 | if ($word['docs'] == 0 | $word['docs'] < $llimf) { 105 | $mis[] = $word['keyword']; 106 | } 107 | } 108 | if (count($mis) > 0) { 109 | foreach ($mis as $m) { 110 | $re = MakeSuggestion($m, $ln_sph); 111 | if ($re) { 112 | if($m!=$re) 113 | $suggested[$m] = $re; 114 | } 115 | } 116 | if(count($words) ==1 && empty($suggested)) { 117 | return false; 118 | } 119 | $phrase = explode(' ', $query); 120 | foreach ($phrase as $k => $word) { 121 | if (isset($suggested[strtolower($word)])) 122 | $phrase[$k] = $suggested[strtolower($word)]; 123 | } 124 | $phrase = implode(' ', $phrase); 125 | return $phrase; 126 | }else{ 127 | return false; 128 | } 129 | } 130 | 131 | ?> 132 | -------------------------------------------------------------------------------- /scripts/suggest/suggest.php: -------------------------------------------------------------------------------- 1 | SetMatchMode ( SPH_MATCH_EXTENDED2 ); 82 | $cl->SetRankingMode ( SPH_RANK_WORDCOUNT ); 83 | $cl->SetFilterRange ( "len", $len-$delta, $len+$delta ); 84 | $cl->SetSelect ( "*, @weight+$delta-abs(len-$len) AS myrank" ); 85 | $cl->SetSortMode ( SPH_SORT_EXTENDED, "myrank DESC, freq DESC" ); 86 | $cl->SetArrayResult ( true ); 87 | 88 | // pull top-N best trigram matches and run them through Levenshtein 89 | $res = $cl->Query ( $query, "suggest", 0, TOP_COUNT ); 90 | 91 | if ( !$res || !$res["matches"] ) 92 | return false; 93 | 94 | if ( SUGGEST_DEBUG ) 95 | { 96 | print "--- DEBUG START ---\n"; 97 | 98 | foreach ( $res["matches"] as $match ) 99 | { 100 | $w = $match["keyword"]; 101 | $myrank = @$match["attrs"]["myrank"]; 102 | if ( $myrank ) 103 | $myrank = ", myrank=$myrank"; 104 | $levdist = levenshtein ( $keyword, $w ); 105 | 106 | print "id=$match[id], weight=$match[weight], freq={$match[attrs][freq]}{$myrank}, word=$w, levdist=$levdist\n"; 107 | } 108 | 109 | print "--- DEBUG END ---\n"; 110 | } 111 | 112 | // further restrict trigram matches with a sane Levenshtein distance limit 113 | foreach ( $res["matches"] as $match ) 114 | { 115 | $suggested = $match["attrs"]["keyword"]; 116 | if ( levenshtein ( $keyword, $suggested )<=LEVENSHTEIN_THRESHOLD ) 117 | return $suggested; 118 | } 119 | return $keyword; 120 | } 121 | 122 | /// main 123 | if ( $_SERVER["argc"]<2 ) 124 | { 125 | die ( "usage:\n" 126 | . "php suggest.php --builddict\treads stopwords from stdin, prints SQL dump of the dictionary to stdout\n" 127 | . "php suggest.php --query WORD\tqueries Sphinx, prints suggestion\n" ); 128 | } 129 | 130 | if ( $_SERVER["argv"][1]=="--builddict" ) 131 | { 132 | $in = fopen ( "php://stdin", "r" ); 133 | $out = fopen ( "php://stdout", "w+" ); 134 | BuildDictionarySQL ( $out, $in ); 135 | } 136 | 137 | if ( $_SERVER["argv"][1]=="--query" ) 138 | { 139 | mysql_connect ( "localhost", "root", "" ) or die ( "mysql_connect() failed: ".mysql_error() ); 140 | mysql_select_db ( "test" ) or die ( "mysql_select_db() failed: ".mysql_error() ); 141 | 142 | $keyword = $_SERVER["argv"][2]; 143 | printf ( "keyword: %s\nsuggestion: %s\n", $keyword, MakeSuggestion($keyword) ); 144 | } 145 | -------------------------------------------------------------------------------- /suggestcompleteexcerpts.php: -------------------------------------------------------------------------------- 1 | prepare("SELECT * FROM $indexes WHERE MATCH(:match) LIMIT $start,$offset OPTION ranker=sph04,field_weights=(title=100,content=1)"); 21 | $stmt->bindValue(':match', $query,PDO::PARAM_STR); 22 | $stmt->execute(); 23 | $rows = $stmt->fetchAll(); 24 | 25 | $meta = $ln_sph->query("SHOW META")->fetchAll(); 26 | foreach($meta as $m) { 27 | $meta_map[$m['Variable_name']] = $m['Value']; 28 | } 29 | $total_found = $meta_map['total_found']; 30 | $total = $$meta_map['total']; 31 | $ids = array(); 32 | $tmpdocs = array(); 33 | if (count($rows) > 0) { 34 | foreach ($rows as $v) { 35 | $ids[] = $v['id']; 36 | } 37 | $q = "SELECT id, title , content FROM docs WHERE id IN (" . implode(',', $ids) . ")"; 38 | foreach ($ln->query($q) as $row) { 39 | $tmpdocs[$row['id']] = array('title' => $row['title'], 'content' => $row['content']); 40 | } 41 | foreach ($ids as $id) { 42 | $docs[] = $tmpdocs[$id]; 43 | } 44 | } else { 45 | $words = array(); 46 | foreach($meta_map as $k=>$v) { 47 | if(preg_match('/keyword\[\d+]/', $k)) { 48 | preg_match('/\d+/', $k,$key); 49 | $key = $key[0]; 50 | $words[$key]['keyword'] = $v; 51 | } 52 | if(preg_match('/docs\[\d+]/', $k)) { 53 | preg_match('/\d+/', $k,$key); 54 | $key = $key[0]; 55 | $words[$key]['docs'] = $v; 56 | } 57 | } 58 | $suggest = MakePhaseSuggestion($words, $query, $ln_sph); 59 | } 60 | } 61 | ?> 62 | 66 |
67 | 76 |
77 |

Simple autocomplete on title

78 |
79 |
80 |
81 |

Autocomplete is made using star on a titles index (with infixes).

82 |

Start typing in the field below

83 | 91 |
92 |
93 | 94 |
95 |
96 |

97 | Did you mean 98 | ? 99 |

100 |
101 |
102 | 103 |
104 | 0): ?> 105 |

106 | 107 | Total found: 108 | 109 |

110 |
111 | 112 |
113 |
114 |

115 | 116 |

117 |

118 | 119 |

120 | 121 |
122 |
123 | 124 |
125 | 126 |

Nothing found!

127 | 128 |
129 | 133 | -------------------------------------------------------------------------------- /qsuggest.php: -------------------------------------------------------------------------------- 1 | prepare("SELECT * FROM $indexes WHERE MATCH(:match) LIMIT $start,$offset OPTION ranker=sph04,field_weights=(title=100,content=1)"); 21 | $stmt->bindValue(':match', $query,PDO::PARAM_STR); 22 | $stmt->execute(); 23 | $rows = $stmt->fetchAll(); 24 | $meta = $ln_sph->query("SHOW META")->fetchAll(); 25 | foreach($meta as $m) { 26 | $meta_map[$m['Variable_name']] = $m['Value']; 27 | } 28 | $total_found = $meta_map['total_found']; 29 | $total = $meta_map['total']; 30 | $ids = array(); 31 | $tmpdocs = array(); 32 | if (count($rows)> 0) { 33 | foreach ($rows as $v) { 34 | $ids[] = $v['id']; 35 | } 36 | $q = "SELECT id,title ,content FROM docs WHERE id IN (" . implode(',', $ids) . ")"; 37 | foreach ($ln->query($q) as $row) { 38 | $tmpdocs[$row['id']] = array('title' => $row['title'], 'content' => $row['content']); 39 | } 40 | foreach ($ids as $id) { 41 | $docs[] = $tmpdocs[$id]; 42 | } 43 | } else { 44 | $words = array(); 45 | foreach($meta_map as $k=>$v) { 46 | 47 | if(preg_match('/keyword\[\d+]/', $k)) { 48 | preg_match('/\d+/', $k,$key); 49 | $key = $key[0]; 50 | $words[$key]['keyword'] = $v; 51 | } 52 | if(preg_match('/docs\[\d+]/', $k)) { 53 | preg_match('/\d+/', $k,$key); 54 | $key = $key[0]; 55 | $words[$key]['docs'] = $v; 56 | } 57 | } 58 | $suggest = MakeMultiQSuggest($words, $query,$indexes, $ln_sph); 59 | } 60 | } 61 | ?> 62 | 66 |
67 | 76 |
77 |

Demo autocomplete with CALL SUGGEST

78 |
79 |
80 |
81 |

82 | Autocomplete is made using star on a titles index (with infixes).
Correction 83 | suggest can be made inside a phrase , by trying to find a suggestion 84 | for each wrong typed word or word with low hits.
85 | This example uses the new CALL SUGGEST function and requires Sphinx 2.3.2-beta or newer.
86 | CALL SUGGEST works only on indexes with infixes, so we need to reindex the main index with infixing. 87 |

88 |

Start typing in the field below

89 | 97 |
98 |
99 | 100 |
101 |
102 |

103 | Did you mean 104 | ? 105 |

106 |
107 |
108 | 109 |

110 | 111 | Total found: 112 | 113 |

114 |
115 | 0): ?> 116 |
117 | 118 |
119 |
120 |

121 | 122 |

123 |

124 | 125 |

126 | 127 |
128 |
129 | 130 |
131 | 132 |

Nothing found!

133 | 134 |
135 | 139 | -------------------------------------------------------------------------------- /suggestcomplete.php: -------------------------------------------------------------------------------- 1 | prepare("SELECT * FROM $indexes WHERE MATCH(:match) LIMIT $start,$offset OPTION ranker=sph04,field_weights=(title=100,content=1)"); 21 | $stmt->bindValue(':match', $query,PDO::PARAM_STR); 22 | $stmt->execute(); 23 | $rows = $stmt->fetchAll(); 24 | $meta = $ln_sph->query("SHOW META")->fetchAll(); 25 | foreach($meta as $m) { 26 | $meta_map[$m['Variable_name']] = $m['Value']; 27 | } 28 | $total_found = $meta_map['total_found']; 29 | $total = $meta_map['total']; 30 | $ids = array(); 31 | $tmpdocs = array(); 32 | if (count($rows)> 0) { 33 | foreach ($rows as $v) { 34 | $ids[] = $v['id']; 35 | } 36 | $q = "SELECT id,title ,content FROM docs WHERE id IN (" . implode(',', $ids) . ")"; 37 | foreach ($ln->query($q) as $row) { 38 | $tmpdocs[$row['id']] = array('title' => $row['title'], 'content' => $row['content']); 39 | } 40 | foreach ($ids as $id) { 41 | $docs[] = $tmpdocs[$id]; 42 | } 43 | } else { 44 | $words = array(); 45 | foreach($meta_map as $k=>$v) { 46 | 47 | if(preg_match('/keyword\[\d+]/', $k)) { 48 | preg_match('/\d+/', $k,$key); 49 | $key = $key[0]; 50 | $words[$key]['keyword'] = $v; 51 | } 52 | if(preg_match('/docs\[\d+]/', $k)) { 53 | preg_match('/\d+/', $k,$key); 54 | $key = $key[0]; 55 | $words[$key]['docs'] = $v; 56 | } 57 | } 58 | $suggest = MakePhaseSuggestion($words, $query, $ln_sph); 59 | } 60 | } 61 | ?> 62 | 66 |
67 | 76 |
77 |

Demo autocomplete with correction suggestion

78 |
79 |
80 |
81 |

82 | Autocomplete is made using star on a titles index (with infixes).
Correction 83 | suggest can be made inside a phrase , by trying to find a suggestion 84 | for each wrong typed word or word with low hits.
Trigrams are 85 | used in the process and there are also sane checks ( based on length 86 | and levenshtein algorithm).
It does not guarantee the new 87 | corrected phrase will do matching.This can be done by doing a query 88 | with the new phrase. 89 |

90 |

Start typing in the field below

91 | 99 |
100 |
101 | 102 |
103 |
104 |

105 | Did you mean 106 | ? 107 |

108 |
109 |
110 | 111 |

112 | 113 | Total found: 114 | 115 |

116 |
117 | 0): ?> 118 |
119 | 120 |
121 |
122 |

123 | 124 |

125 |

126 | 127 |

128 | 129 |
130 |
131 | 132 |
133 | 134 |

Nothing found!

135 | 136 |
137 | 141 | -------------------------------------------------------------------------------- /css/bootstrap-responsive.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Responsive v2.0.4 3 | * 4 | * Copyright 2012 Twitter, Inc 5 | * Licensed under the Apache License v2.0 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Designed and built with all the love in the world @twitter by @mdo and @fat. 9 | */.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;content:""}.clearfix:after{clear:both}.hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.input-block-level{display:block;width:100%;min-height:28px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;box-sizing:border-box}.hidden{display:none;visibility:hidden}.visible-phone{display:none!important}.visible-tablet{display:none!important}.hidden-desktop{display:none!important}@media(max-width:767px){.visible-phone{display:inherit!important}.hidden-phone{display:none!important}.hidden-desktop{display:inherit!important}.visible-desktop{display:none!important}}@media(min-width:768px) and (max-width:979px){.visible-tablet{display:inherit!important}.hidden-tablet{display:none!important}.hidden-desktop{display:inherit!important}.visible-desktop{display:none!important}}@media(max-width:480px){.nav-collapse{-webkit-transform:translate3d(0,0,0)}.page-header h1 small{display:block;line-height:18px}input[type="checkbox"],input[type="radio"]{border:1px solid #ccc}.form-horizontal .control-group>label{float:none;width:auto;padding-top:0;text-align:left}.form-horizontal .controls{margin-left:0}.form-horizontal .control-list{padding-top:0}.form-horizontal .form-actions{padding-right:10px;padding-left:10px}.modal{position:absolute;top:10px;right:10px;left:10px;width:auto;margin:0}.modal.fade.in{top:auto}.modal-header .close{padding:10px;margin:-10px}.carousel-caption{position:static}}@media(max-width:767px){body{padding-right:20px;padding-left:20px}.navbar-fixed-top,.navbar-fixed-bottom{margin-right:-20px;margin-left:-20px}.container-fluid{padding:0}.dl-horizontal dt{float:none;width:auto;clear:none;text-align:left}.dl-horizontal dd{margin-left:0}.container{width:auto}.row-fluid{width:100%}.row,.thumbnails{margin-left:0}[class*="span"],.row-fluid [class*="span"]{display:block;float:none;width:auto;margin-left:0}.input-large,.input-xlarge,.input-xxlarge,input[class*="span"],select[class*="span"],textarea[class*="span"],.uneditable-input{display:block;width:100%;min-height:28px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;box-sizing:border-box}.input-prepend input,.input-append input,.input-prepend input[class*="span"],.input-append input[class*="span"]{display:inline-block;width:auto}}@media(min-width:768px) and (max-width:979px){.row{margin-left:-20px;*zoom:1}.row:before,.row:after{display:table;content:""}.row:after{clear:both}[class*="span"]{float:left;margin-left:20px}.container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:724px}.span12{width:724px}.span11{width:662px}.span10{width:600px}.span9{width:538px}.span8{width:476px}.span7{width:414px}.span6{width:352px}.span5{width:290px}.span4{width:228px}.span3{width:166px}.span2{width:104px}.span1{width:42px}.offset12{margin-left:764px}.offset11{margin-left:702px}.offset10{margin-left:640px}.offset9{margin-left:578px}.offset8{margin-left:516px}.offset7{margin-left:454px}.offset6{margin-left:392px}.offset5{margin-left:330px}.offset4{margin-left:268px}.offset3{margin-left:206px}.offset2{margin-left:144px}.offset1{margin-left:82px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:28px;margin-left:2.762430939%;*margin-left:2.709239449638298%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .span12{width:99.999999993%;*width:99.9468085036383%}.row-fluid .span11{width:91.436464082%;*width:91.38327259263829%}.row-fluid .span10{width:82.87292817100001%;*width:82.8197366816383%}.row-fluid .span9{width:74.30939226%;*width:74.25620077063829%}.row-fluid .span8{width:65.74585634900001%;*width:65.6926648596383%}.row-fluid .span7{width:57.182320438000005%;*width:57.129128948638304%}.row-fluid .span6{width:48.618784527%;*width:48.5655930376383%}.row-fluid .span5{width:40.055248616%;*width:40.0020571266383%}.row-fluid .span4{width:31.491712705%;*width:31.4385212156383%}.row-fluid .span3{width:22.928176794%;*width:22.874985304638297%}.row-fluid .span2{width:14.364640883%;*width:14.311449393638298%}.row-fluid .span1{width:5.801104972%;*width:5.747913482638298%}input,textarea,.uneditable-input{margin-left:0}input.span12,textarea.span12,.uneditable-input.span12{width:714px}input.span11,textarea.span11,.uneditable-input.span11{width:652px}input.span10,textarea.span10,.uneditable-input.span10{width:590px}input.span9,textarea.span9,.uneditable-input.span9{width:528px}input.span8,textarea.span8,.uneditable-input.span8{width:466px}input.span7,textarea.span7,.uneditable-input.span7{width:404px}input.span6,textarea.span6,.uneditable-input.span6{width:342px}input.span5,textarea.span5,.uneditable-input.span5{width:280px}input.span4,textarea.span4,.uneditable-input.span4{width:218px}input.span3,textarea.span3,.uneditable-input.span3{width:156px}input.span2,textarea.span2,.uneditable-input.span2{width:94px}input.span1,textarea.span1,.uneditable-input.span1{width:32px}}@media(min-width:1200px){.row{margin-left:-30px;*zoom:1}.row:before,.row:after{display:table;content:""}.row:after{clear:both}[class*="span"]{float:left;margin-left:30px}.container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:1170px}.span12{width:1170px}.span11{width:1070px}.span10{width:970px}.span9{width:870px}.span8{width:770px}.span7{width:670px}.span6{width:570px}.span5{width:470px}.span4{width:370px}.span3{width:270px}.span2{width:170px}.span1{width:70px}.offset12{margin-left:1230px}.offset11{margin-left:1130px}.offset10{margin-left:1030px}.offset9{margin-left:930px}.offset8{margin-left:830px}.offset7{margin-left:730px}.offset6{margin-left:630px}.offset5{margin-left:530px}.offset4{margin-left:430px}.offset3{margin-left:330px}.offset2{margin-left:230px}.offset1{margin-left:130px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:28px;margin-left:2.564102564%;*margin-left:2.510911074638298%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .span12{width:100%;*width:99.94680851063829%}.row-fluid .span11{width:91.45299145300001%;*width:91.3997999636383%}.row-fluid .span10{width:82.905982906%;*width:82.8527914166383%}.row-fluid .span9{width:74.358974359%;*width:74.30578286963829%}.row-fluid .span8{width:65.81196581200001%;*width:65.7587743226383%}.row-fluid .span7{width:57.264957265%;*width:57.2117657756383%}.row-fluid .span6{width:48.717948718%;*width:48.6647572286383%}.row-fluid .span5{width:40.170940171000005%;*width:40.117748681638304%}.row-fluid .span4{width:31.623931624%;*width:31.5707401346383%}.row-fluid .span3{width:23.076923077%;*width:23.0237315876383%}.row-fluid .span2{width:14.529914530000001%;*width:14.4767230406383%}.row-fluid .span1{width:5.982905983%;*width:5.929714493638298%}input,textarea,.uneditable-input{margin-left:0}input.span12,textarea.span12,.uneditable-input.span12{width:1160px}input.span11,textarea.span11,.uneditable-input.span11{width:1060px}input.span10,textarea.span10,.uneditable-input.span10{width:960px}input.span9,textarea.span9,.uneditable-input.span9{width:860px}input.span8,textarea.span8,.uneditable-input.span8{width:760px}input.span7,textarea.span7,.uneditable-input.span7{width:660px}input.span6,textarea.span6,.uneditable-input.span6{width:560px}input.span5,textarea.span5,.uneditable-input.span5{width:460px}input.span4,textarea.span4,.uneditable-input.span4{width:360px}input.span3,textarea.span3,.uneditable-input.span3{width:260px}input.span2,textarea.span2,.uneditable-input.span2{width:160px}input.span1,textarea.span1,.uneditable-input.span1{width:60px}.thumbnails{margin-left:-30px}.thumbnails>li{margin-left:30px}.row-fluid .thumbnails{margin-left:0}}@media(max-width:979px){body{padding-top:0}.navbar-fixed-top,.navbar-fixed-bottom{position:static}.navbar-fixed-top{margin-bottom:18px}.navbar-fixed-bottom{margin-top:18px}.navbar-fixed-top .navbar-inner,.navbar-fixed-bottom .navbar-inner{padding:5px}.navbar .container{width:auto;padding:0}.navbar .brand{padding-right:10px;padding-left:10px;margin:0 0 0 -5px}.nav-collapse{clear:both}.nav-collapse .nav{float:none;margin:0 0 9px}.nav-collapse .nav>li{float:none}.nav-collapse .nav>li>a{margin-bottom:2px}.nav-collapse .nav>.divider-vertical{display:none}.nav-collapse .nav .nav-header{color:#999;text-shadow:none}.nav-collapse .nav>li>a,.nav-collapse .dropdown-menu a{padding:6px 15px;font-weight:bold;color:#999;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.nav-collapse .btn{padding:4px 10px 4px;font-weight:normal;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.nav-collapse .dropdown-menu li+li a{margin-bottom:2px}.nav-collapse .nav>li>a:hover,.nav-collapse .dropdown-menu a:hover{background-color:#222}.nav-collapse.in .btn-group{padding:0;margin-top:5px}.nav-collapse .dropdown-menu{position:static;top:auto;left:auto;display:block;float:none;max-width:none;padding:0;margin:0 15px;background-color:transparent;border:0;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.nav-collapse .dropdown-menu:before,.nav-collapse .dropdown-menu:after{display:none}.nav-collapse .dropdown-menu .divider{display:none}.nav-collapse .navbar-form,.nav-collapse .navbar-search{float:none;padding:9px 15px;margin:9px 0;border-top:1px solid #222;border-bottom:1px solid #222;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1);box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1)}.navbar .nav-collapse .nav.pull-right{float:none;margin-left:0}.nav-collapse,.nav-collapse.collapse{height:0;overflow:hidden}.navbar .btn-navbar{display:block}.navbar-static .navbar-inner{padding-right:10px;padding-left:10px}}@media(min-width:980px){.nav-collapse.collapse{height:auto!important;overflow:visible!important}} 10 | -------------------------------------------------------------------------------- /js/bootstrap-typeahead.js: -------------------------------------------------------------------------------- 1 | /* ============================================================= 2 | * bootstrap-typeahead.js v2.0.3 3 | * http://twitter.github.com/bootstrap/javascript.html#typeahead 4 | * ============================================================= 5 | * Copyright 2012 Twitter, Inc. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ============================================================ */ 19 | 20 | /* 21 | * 22 | * Modifications by Paul Warelis 23 | * 24 | */ 25 | 26 | !function($){ 27 | 28 | "use strict"; // jshint ;_; 29 | 30 | /* TYPEAHEAD PUBLIC CLASS DEFINITION 31 | * ================================= */ 32 | 33 | var Typeahead = function (element, options) { 34 | this.$element = $(element) 35 | this.options = $.extend({}, $.fn.typeahead.defaults, options) 36 | this.matcher = this.options.matcher || this.matcher 37 | this.sorter = this.options.sorter || this.sorter 38 | this.highlighter = this.options.highlighter || this.highlighter 39 | this.updater = this.options.updater || this.updater 40 | this.$menu = $(this.options.menu).appendTo('body') 41 | if (this.options.ajax) { 42 | var ajax = this.options.ajax; 43 | if (typeof ajax == "string") { 44 | ajax = { url:ajax }; 45 | } 46 | this.ajax = { 47 | url : ajax.url, 48 | timeout : ajax.timeout || 300, 49 | method: ajax.method || "post", 50 | triggerLength : ajax.triggerLength || 3, 51 | loadingClass : ajax.loadingClass || null, 52 | displayField : ajax.displayField || null, 53 | preDispatch : ajax.preDispatch || null, 54 | preProcess : ajax.preProcess || null 55 | } 56 | this.query = ""; 57 | } else { 58 | this.source = this.options.source 59 | this.ajax = null; 60 | } 61 | this.shown = false 62 | this.listen() 63 | } 64 | 65 | Typeahead.prototype = { 66 | 67 | constructor: Typeahead, 68 | 69 | select: function () { 70 | var val = this.$menu.find('.active').attr('data-value') 71 | this.$element 72 | .val(this.updater(val)) 73 | .change() 74 | return this.hide() 75 | }, 76 | 77 | updater: function (item) { 78 | return item 79 | }, 80 | 81 | show: function () { 82 | var pos = $.extend({}, this.$element.offset(), { 83 | height: this.$element[0].offsetHeight 84 | }) 85 | 86 | this.$menu.css({ 87 | top: pos.top + pos.height, 88 | left: pos.left 89 | }) 90 | 91 | this.$menu.show() 92 | this.shown = true 93 | return this 94 | }, 95 | 96 | hide: function () { 97 | this.$menu.hide() 98 | this.shown = false 99 | return this 100 | }, 101 | 102 | ajaxLookup: function () { 103 | 104 | var query = this.$element.val(); 105 | 106 | if (query == this.query) { 107 | return this; 108 | } 109 | 110 | // Query changed 111 | this.query = query 112 | 113 | // Cancel last timer if set 114 | if (this.ajax.timerId) { 115 | clearTimeout(this.ajax.timerId); 116 | this.ajax.timerId = null; 117 | } 118 | 119 | if (!query || query.length < this.ajax.triggerLength) { 120 | // cancel the ajax callback if in progress 121 | if (this.ajax.xhr) { 122 | this.ajax.xhr.abort(); 123 | this.ajax.xhr = null; 124 | this.ajaxToggleLoadClass(false); 125 | } 126 | return this.shown ? this.hide() : this 127 | } 128 | 129 | function execute() { 130 | this.ajaxToggleLoadClass(true); 131 | 132 | // Cancel last call if already in progress 133 | if (this.ajax.xhr) this.ajax.xhr.abort(); 134 | 135 | var params = this.ajax.preDispatch ? this.ajax.preDispatch(query) : { query : query } 136 | var jAjax = (this.ajax.method == "post") ? $.post : $.get; 137 | this.ajax.xhr = jAjax(this.ajax.url, params, $.proxy(this.ajaxSource, this)); 138 | this.ajax.timerId = null; 139 | } 140 | 141 | // Query is good to send, set a timer 142 | this.ajax.timerId = setTimeout($.proxy(execute, this), this.ajax.timeout); 143 | 144 | return this; 145 | }, 146 | 147 | ajaxSource: function (data) { 148 | this.ajaxToggleLoadClass(false); 149 | 150 | var that = this, items 151 | 152 | if (!this.ajax.xhr) return; 153 | 154 | if (this.ajax.preProcess) { 155 | data = this.ajax.preProcess(data); 156 | } 157 | // Save for selection retreival 158 | this.ajax.data = data; 159 | 160 | items = $.grep(data, function (item) { 161 | if (that.ajax.displayField) { 162 | item = item[that.ajax.displayField] 163 | } 164 | if (that.matcher(item)) return item 165 | }) 166 | 167 | items = this.sorter(items) 168 | 169 | if (!items.length) { 170 | return this.shown ? this.hide() : this 171 | } 172 | 173 | this.ajax.xhr = null; 174 | return this.render(items.slice(0, this.options.items)).show() 175 | }, 176 | 177 | ajaxToggleLoadClass: function (enable) { 178 | if (!this.ajax.loadingClass) return; 179 | this.$element.toggleClass(this.ajax.loadingClass, enable); 180 | }, 181 | 182 | lookup: function (event) { 183 | var that = this, items 184 | 185 | this.query = this.$element.val() 186 | 187 | if (!this.query) { 188 | return this.shown ? this.hide() : this 189 | } 190 | 191 | items = $.grep(this.source, function (item) { 192 | return that.matcher(item) 193 | }) 194 | 195 | items = this.sorter(items) 196 | 197 | if (!items.length) { 198 | return this.shown ? this.hide() : this 199 | } 200 | 201 | return this.render(items.slice(0, this.options.items)).show() 202 | }, 203 | 204 | matcher: function (item) { 205 | return true; 206 | }, 207 | 208 | sorter: function (items) { 209 | var beginswith = [], 210 | caseSensitive = [], 211 | caseInsensitive = [], 212 | item 213 | 214 | while (item = items.shift()) { 215 | if (this.ajax && this.ajax.displayField) { 216 | item = item[this.ajax.displayField] 217 | } 218 | if (!item.toLowerCase().indexOf(this.query.toLowerCase())) beginswith.push(item) 219 | else if (~item.indexOf(this.query)) caseSensitive.push(item) 220 | else caseInsensitive.push(item) 221 | } 222 | 223 | return beginswith.concat(caseSensitive, caseInsensitive) 224 | }, 225 | 226 | highlighter: function (item) { 227 | var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&') 228 | return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) { 229 | return '' + match + '' 230 | }) 231 | }, 232 | 233 | render: function (items) { 234 | var that = this 235 | 236 | items = $(items).map(function (i, item) { 237 | i = $(that.options.item).attr('data-value', item) 238 | i.find('a').html(that.highlighter(item)) 239 | return i[0] 240 | }) 241 | 242 | items.first().addClass('active') 243 | this.$menu.html(items) 244 | return this 245 | }, 246 | 247 | next: function (event) { 248 | var active = this.$menu.find('.active').removeClass('active'), 249 | next = active.next() 250 | 251 | if (!next.length) { 252 | next = $(this.$menu.find('li')[0]) 253 | } 254 | 255 | next.addClass('active') 256 | }, 257 | 258 | prev: function (event) { 259 | var active = this.$menu.find('.active').removeClass('active'), 260 | prev = active.prev() 261 | 262 | if (!prev.length) { 263 | prev = this.$menu.find('li').last() 264 | } 265 | 266 | prev.addClass('active') 267 | }, 268 | 269 | listen: function () { 270 | this.$element 271 | .on('blur', $.proxy(this.blur, this)) 272 | .on('keypress', $.proxy(this.keypress, this)) 273 | .on('keyup', $.proxy(this.keyup, this)) 274 | 275 | // Firefox needs this too 276 | this.$element.on('keydown', $.proxy(this.keypress, this)) 277 | 278 | this.$menu 279 | .on('click', $.proxy(this.click, this)) 280 | .on('mouseenter', 'li', $.proxy(this.mouseenter, this)) 281 | }, 282 | 283 | keyup: function (e) { 284 | switch(e.keyCode) { 285 | case 40: // down arrow 286 | case 38: // up arrow 287 | break 288 | 289 | case 9: // tab 290 | case 13: // enter 291 | if (!this.shown) return 292 | this.select() 293 | break 294 | 295 | case 27: // escape 296 | if (!this.shown) return 297 | this.hide() 298 | break 299 | 300 | default: 301 | if (this.ajax) this.ajaxLookup() 302 | else this.lookup() 303 | } 304 | 305 | e.stopPropagation() 306 | e.preventDefault() 307 | }, 308 | 309 | keypress: function (e) { 310 | if (!this.shown) return 311 | 312 | switch(e.keyCode) { 313 | case 9: // tab 314 | case 13: // enter 315 | case 27: // escape 316 | e.preventDefault() 317 | break 318 | 319 | case 38: // up arrow 320 | if (e.type != 'keydown') break 321 | e.preventDefault() 322 | this.prev() 323 | break 324 | 325 | case 40: // down arrow 326 | if (e.type != 'keydown') break 327 | e.preventDefault() 328 | this.next() 329 | break 330 | } 331 | 332 | e.stopPropagation() 333 | }, 334 | 335 | blur: function (e) { 336 | var that = this 337 | setTimeout(function () { that.hide() }, 150) 338 | }, 339 | 340 | click: function (e) { 341 | e.stopPropagation() 342 | e.preventDefault() 343 | this.select() 344 | }, 345 | 346 | mouseenter: function (e) { 347 | this.$menu.find('.active').removeClass('active') 348 | $(e.currentTarget).addClass('active') 349 | } 350 | } 351 | 352 | 353 | /* TYPEAHEAD PLUGIN DEFINITION 354 | * =========================== */ 355 | 356 | $.fn.typeahead = function (option) { 357 | return this.each(function () { 358 | var $this = $(this), 359 | data = $this.data('typeahead'), 360 | options = typeof option == 'object' && option 361 | if (!data) $this.data('typeahead', (data = new Typeahead(this, options))) 362 | if (typeof option == 'string') data[option]() 363 | }) 364 | } 365 | 366 | $.fn.typeahead.defaults = { 367 | source: [], 368 | items: 8, 369 | menu: '', 370 | item: '
  • ' 371 | } 372 | 373 | $.fn.typeahead.Constructor = Typeahead 374 | 375 | /* TYPEAHEAD DATA-API 376 | * ================== */ 377 | 378 | $(function () { 379 | $('body').on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) { 380 | var $this = $(this) 381 | if ($this.data('typeahead')) return 382 | e.preventDefault() 383 | $this.typeahead($this.data()) 384 | }) 385 | }) 386 | 387 | }(window.jQuery); -------------------------------------------------------------------------------- /css/bootstrap-responsive.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Responsive v2.0.4 3 | * 4 | * Copyright 2012 Twitter, Inc 5 | * Licensed under the Apache License v2.0 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Designed and built with all the love in the world @twitter by @mdo and @fat. 9 | */ 10 | 11 | .clearfix { 12 | *zoom: 1; 13 | } 14 | 15 | .clearfix:before, 16 | .clearfix:after { 17 | display: table; 18 | content: ""; 19 | } 20 | 21 | .clearfix:after { 22 | clear: both; 23 | } 24 | 25 | .hide-text { 26 | font: 0/0 a; 27 | color: transparent; 28 | text-shadow: none; 29 | background-color: transparent; 30 | border: 0; 31 | } 32 | 33 | .input-block-level { 34 | display: block; 35 | width: 100%; 36 | min-height: 28px; 37 | -webkit-box-sizing: border-box; 38 | -moz-box-sizing: border-box; 39 | -ms-box-sizing: border-box; 40 | box-sizing: border-box; 41 | } 42 | 43 | .hidden { 44 | display: none; 45 | visibility: hidden; 46 | } 47 | 48 | .visible-phone { 49 | display: none !important; 50 | } 51 | 52 | .visible-tablet { 53 | display: none !important; 54 | } 55 | 56 | .hidden-desktop { 57 | display: none !important; 58 | } 59 | 60 | @media (max-width: 767px) { 61 | .visible-phone { 62 | display: inherit !important; 63 | } 64 | .hidden-phone { 65 | display: none !important; 66 | } 67 | .hidden-desktop { 68 | display: inherit !important; 69 | } 70 | .visible-desktop { 71 | display: none !important; 72 | } 73 | } 74 | 75 | @media (min-width: 768px) and (max-width: 979px) { 76 | .visible-tablet { 77 | display: inherit !important; 78 | } 79 | .hidden-tablet { 80 | display: none !important; 81 | } 82 | .hidden-desktop { 83 | display: inherit !important; 84 | } 85 | .visible-desktop { 86 | display: none !important ; 87 | } 88 | } 89 | 90 | @media (max-width: 480px) { 91 | .nav-collapse { 92 | -webkit-transform: translate3d(0, 0, 0); 93 | } 94 | .page-header h1 small { 95 | display: block; 96 | line-height: 18px; 97 | } 98 | input[type="checkbox"], 99 | input[type="radio"] { 100 | border: 1px solid #ccc; 101 | } 102 | .form-horizontal .control-group > label { 103 | float: none; 104 | width: auto; 105 | padding-top: 0; 106 | text-align: left; 107 | } 108 | .form-horizontal .controls { 109 | margin-left: 0; 110 | } 111 | .form-horizontal .control-list { 112 | padding-top: 0; 113 | } 114 | .form-horizontal .form-actions { 115 | padding-right: 10px; 116 | padding-left: 10px; 117 | } 118 | .modal { 119 | position: absolute; 120 | top: 10px; 121 | right: 10px; 122 | left: 10px; 123 | width: auto; 124 | margin: 0; 125 | } 126 | .modal.fade.in { 127 | top: auto; 128 | } 129 | .modal-header .close { 130 | padding: 10px; 131 | margin: -10px; 132 | } 133 | .carousel-caption { 134 | position: static; 135 | } 136 | } 137 | 138 | @media (max-width: 767px) { 139 | body { 140 | padding-right: 20px; 141 | padding-left: 20px; 142 | } 143 | .navbar-fixed-top, 144 | .navbar-fixed-bottom { 145 | margin-right: -20px; 146 | margin-left: -20px; 147 | } 148 | .container-fluid { 149 | padding: 0; 150 | } 151 | .dl-horizontal dt { 152 | float: none; 153 | width: auto; 154 | clear: none; 155 | text-align: left; 156 | } 157 | .dl-horizontal dd { 158 | margin-left: 0; 159 | } 160 | .container { 161 | width: auto; 162 | } 163 | .row-fluid { 164 | width: 100%; 165 | } 166 | .row, 167 | .thumbnails { 168 | margin-left: 0; 169 | } 170 | [class*="span"], 171 | .row-fluid [class*="span"] { 172 | display: block; 173 | float: none; 174 | width: auto; 175 | margin-left: 0; 176 | } 177 | .input-large, 178 | .input-xlarge, 179 | .input-xxlarge, 180 | input[class*="span"], 181 | select[class*="span"], 182 | textarea[class*="span"], 183 | .uneditable-input { 184 | display: block; 185 | width: 100%; 186 | min-height: 28px; 187 | -webkit-box-sizing: border-box; 188 | -moz-box-sizing: border-box; 189 | -ms-box-sizing: border-box; 190 | box-sizing: border-box; 191 | } 192 | .input-prepend input, 193 | .input-append input, 194 | .input-prepend input[class*="span"], 195 | .input-append input[class*="span"] { 196 | display: inline-block; 197 | width: auto; 198 | } 199 | } 200 | 201 | @media (min-width: 768px) and (max-width: 979px) { 202 | .row { 203 | margin-left: -20px; 204 | *zoom: 1; 205 | } 206 | .row:before, 207 | .row:after { 208 | display: table; 209 | content: ""; 210 | } 211 | .row:after { 212 | clear: both; 213 | } 214 | [class*="span"] { 215 | float: left; 216 | margin-left: 20px; 217 | } 218 | .container, 219 | .navbar-fixed-top .container, 220 | .navbar-fixed-bottom .container { 221 | width: 724px; 222 | } 223 | .span12 { 224 | width: 724px; 225 | } 226 | .span11 { 227 | width: 662px; 228 | } 229 | .span10 { 230 | width: 600px; 231 | } 232 | .span9 { 233 | width: 538px; 234 | } 235 | .span8 { 236 | width: 476px; 237 | } 238 | .span7 { 239 | width: 414px; 240 | } 241 | .span6 { 242 | width: 352px; 243 | } 244 | .span5 { 245 | width: 290px; 246 | } 247 | .span4 { 248 | width: 228px; 249 | } 250 | .span3 { 251 | width: 166px; 252 | } 253 | .span2 { 254 | width: 104px; 255 | } 256 | .span1 { 257 | width: 42px; 258 | } 259 | .offset12 { 260 | margin-left: 764px; 261 | } 262 | .offset11 { 263 | margin-left: 702px; 264 | } 265 | .offset10 { 266 | margin-left: 640px; 267 | } 268 | .offset9 { 269 | margin-left: 578px; 270 | } 271 | .offset8 { 272 | margin-left: 516px; 273 | } 274 | .offset7 { 275 | margin-left: 454px; 276 | } 277 | .offset6 { 278 | margin-left: 392px; 279 | } 280 | .offset5 { 281 | margin-left: 330px; 282 | } 283 | .offset4 { 284 | margin-left: 268px; 285 | } 286 | .offset3 { 287 | margin-left: 206px; 288 | } 289 | .offset2 { 290 | margin-left: 144px; 291 | } 292 | .offset1 { 293 | margin-left: 82px; 294 | } 295 | .row-fluid { 296 | width: 100%; 297 | *zoom: 1; 298 | } 299 | .row-fluid:before, 300 | .row-fluid:after { 301 | display: table; 302 | content: ""; 303 | } 304 | .row-fluid:after { 305 | clear: both; 306 | } 307 | .row-fluid [class*="span"] { 308 | display: block; 309 | float: left; 310 | width: 100%; 311 | min-height: 28px; 312 | margin-left: 2.762430939%; 313 | *margin-left: 2.709239449638298%; 314 | -webkit-box-sizing: border-box; 315 | -moz-box-sizing: border-box; 316 | -ms-box-sizing: border-box; 317 | box-sizing: border-box; 318 | } 319 | .row-fluid [class*="span"]:first-child { 320 | margin-left: 0; 321 | } 322 | .row-fluid .span12 { 323 | width: 99.999999993%; 324 | *width: 99.9468085036383%; 325 | } 326 | .row-fluid .span11 { 327 | width: 91.436464082%; 328 | *width: 91.38327259263829%; 329 | } 330 | .row-fluid .span10 { 331 | width: 82.87292817100001%; 332 | *width: 82.8197366816383%; 333 | } 334 | .row-fluid .span9 { 335 | width: 74.30939226%; 336 | *width: 74.25620077063829%; 337 | } 338 | .row-fluid .span8 { 339 | width: 65.74585634900001%; 340 | *width: 65.6926648596383%; 341 | } 342 | .row-fluid .span7 { 343 | width: 57.182320438000005%; 344 | *width: 57.129128948638304%; 345 | } 346 | .row-fluid .span6 { 347 | width: 48.618784527%; 348 | *width: 48.5655930376383%; 349 | } 350 | .row-fluid .span5 { 351 | width: 40.055248616%; 352 | *width: 40.0020571266383%; 353 | } 354 | .row-fluid .span4 { 355 | width: 31.491712705%; 356 | *width: 31.4385212156383%; 357 | } 358 | .row-fluid .span3 { 359 | width: 22.928176794%; 360 | *width: 22.874985304638297%; 361 | } 362 | .row-fluid .span2 { 363 | width: 14.364640883%; 364 | *width: 14.311449393638298%; 365 | } 366 | .row-fluid .span1 { 367 | width: 5.801104972%; 368 | *width: 5.747913482638298%; 369 | } 370 | input, 371 | textarea, 372 | .uneditable-input { 373 | margin-left: 0; 374 | } 375 | input.span12, 376 | textarea.span12, 377 | .uneditable-input.span12 { 378 | width: 714px; 379 | } 380 | input.span11, 381 | textarea.span11, 382 | .uneditable-input.span11 { 383 | width: 652px; 384 | } 385 | input.span10, 386 | textarea.span10, 387 | .uneditable-input.span10 { 388 | width: 590px; 389 | } 390 | input.span9, 391 | textarea.span9, 392 | .uneditable-input.span9 { 393 | width: 528px; 394 | } 395 | input.span8, 396 | textarea.span8, 397 | .uneditable-input.span8 { 398 | width: 466px; 399 | } 400 | input.span7, 401 | textarea.span7, 402 | .uneditable-input.span7 { 403 | width: 404px; 404 | } 405 | input.span6, 406 | textarea.span6, 407 | .uneditable-input.span6 { 408 | width: 342px; 409 | } 410 | input.span5, 411 | textarea.span5, 412 | .uneditable-input.span5 { 413 | width: 280px; 414 | } 415 | input.span4, 416 | textarea.span4, 417 | .uneditable-input.span4 { 418 | width: 218px; 419 | } 420 | input.span3, 421 | textarea.span3, 422 | .uneditable-input.span3 { 423 | width: 156px; 424 | } 425 | input.span2, 426 | textarea.span2, 427 | .uneditable-input.span2 { 428 | width: 94px; 429 | } 430 | input.span1, 431 | textarea.span1, 432 | .uneditable-input.span1 { 433 | width: 32px; 434 | } 435 | } 436 | 437 | @media (min-width: 1200px) { 438 | .row { 439 | margin-left: -30px; 440 | *zoom: 1; 441 | } 442 | .row:before, 443 | .row:after { 444 | display: table; 445 | content: ""; 446 | } 447 | .row:after { 448 | clear: both; 449 | } 450 | [class*="span"] { 451 | float: left; 452 | margin-left: 30px; 453 | } 454 | .container, 455 | .navbar-fixed-top .container, 456 | .navbar-fixed-bottom .container { 457 | width: 1170px; 458 | } 459 | .span12 { 460 | width: 1170px; 461 | } 462 | .span11 { 463 | width: 1070px; 464 | } 465 | .span10 { 466 | width: 970px; 467 | } 468 | .span9 { 469 | width: 870px; 470 | } 471 | .span8 { 472 | width: 770px; 473 | } 474 | .span7 { 475 | width: 670px; 476 | } 477 | .span6 { 478 | width: 570px; 479 | } 480 | .span5 { 481 | width: 470px; 482 | } 483 | .span4 { 484 | width: 370px; 485 | } 486 | .span3 { 487 | width: 270px; 488 | } 489 | .span2 { 490 | width: 170px; 491 | } 492 | .span1 { 493 | width: 70px; 494 | } 495 | .offset12 { 496 | margin-left: 1230px; 497 | } 498 | .offset11 { 499 | margin-left: 1130px; 500 | } 501 | .offset10 { 502 | margin-left: 1030px; 503 | } 504 | .offset9 { 505 | margin-left: 930px; 506 | } 507 | .offset8 { 508 | margin-left: 830px; 509 | } 510 | .offset7 { 511 | margin-left: 730px; 512 | } 513 | .offset6 { 514 | margin-left: 630px; 515 | } 516 | .offset5 { 517 | margin-left: 530px; 518 | } 519 | .offset4 { 520 | margin-left: 430px; 521 | } 522 | .offset3 { 523 | margin-left: 330px; 524 | } 525 | .offset2 { 526 | margin-left: 230px; 527 | } 528 | .offset1 { 529 | margin-left: 130px; 530 | } 531 | .row-fluid { 532 | width: 100%; 533 | *zoom: 1; 534 | } 535 | .row-fluid:before, 536 | .row-fluid:after { 537 | display: table; 538 | content: ""; 539 | } 540 | .row-fluid:after { 541 | clear: both; 542 | } 543 | .row-fluid [class*="span"] { 544 | display: block; 545 | float: left; 546 | width: 100%; 547 | min-height: 28px; 548 | margin-left: 2.564102564%; 549 | *margin-left: 2.510911074638298%; 550 | -webkit-box-sizing: border-box; 551 | -moz-box-sizing: border-box; 552 | -ms-box-sizing: border-box; 553 | box-sizing: border-box; 554 | } 555 | .row-fluid [class*="span"]:first-child { 556 | margin-left: 0; 557 | } 558 | .row-fluid .span12 { 559 | width: 100%; 560 | *width: 99.94680851063829%; 561 | } 562 | .row-fluid .span11 { 563 | width: 91.45299145300001%; 564 | *width: 91.3997999636383%; 565 | } 566 | .row-fluid .span10 { 567 | width: 82.905982906%; 568 | *width: 82.8527914166383%; 569 | } 570 | .row-fluid .span9 { 571 | width: 74.358974359%; 572 | *width: 74.30578286963829%; 573 | } 574 | .row-fluid .span8 { 575 | width: 65.81196581200001%; 576 | *width: 65.7587743226383%; 577 | } 578 | .row-fluid .span7 { 579 | width: 57.264957265%; 580 | *width: 57.2117657756383%; 581 | } 582 | .row-fluid .span6 { 583 | width: 48.717948718%; 584 | *width: 48.6647572286383%; 585 | } 586 | .row-fluid .span5 { 587 | width: 40.170940171000005%; 588 | *width: 40.117748681638304%; 589 | } 590 | .row-fluid .span4 { 591 | width: 31.623931624%; 592 | *width: 31.5707401346383%; 593 | } 594 | .row-fluid .span3 { 595 | width: 23.076923077%; 596 | *width: 23.0237315876383%; 597 | } 598 | .row-fluid .span2 { 599 | width: 14.529914530000001%; 600 | *width: 14.4767230406383%; 601 | } 602 | .row-fluid .span1 { 603 | width: 5.982905983%; 604 | *width: 5.929714493638298%; 605 | } 606 | input, 607 | textarea, 608 | .uneditable-input { 609 | margin-left: 0; 610 | } 611 | input.span12, 612 | textarea.span12, 613 | .uneditable-input.span12 { 614 | width: 1160px; 615 | } 616 | input.span11, 617 | textarea.span11, 618 | .uneditable-input.span11 { 619 | width: 1060px; 620 | } 621 | input.span10, 622 | textarea.span10, 623 | .uneditable-input.span10 { 624 | width: 960px; 625 | } 626 | input.span9, 627 | textarea.span9, 628 | .uneditable-input.span9 { 629 | width: 860px; 630 | } 631 | input.span8, 632 | textarea.span8, 633 | .uneditable-input.span8 { 634 | width: 760px; 635 | } 636 | input.span7, 637 | textarea.span7, 638 | .uneditable-input.span7 { 639 | width: 660px; 640 | } 641 | input.span6, 642 | textarea.span6, 643 | .uneditable-input.span6 { 644 | width: 560px; 645 | } 646 | input.span5, 647 | textarea.span5, 648 | .uneditable-input.span5 { 649 | width: 460px; 650 | } 651 | input.span4, 652 | textarea.span4, 653 | .uneditable-input.span4 { 654 | width: 360px; 655 | } 656 | input.span3, 657 | textarea.span3, 658 | .uneditable-input.span3 { 659 | width: 260px; 660 | } 661 | input.span2, 662 | textarea.span2, 663 | .uneditable-input.span2 { 664 | width: 160px; 665 | } 666 | input.span1, 667 | textarea.span1, 668 | .uneditable-input.span1 { 669 | width: 60px; 670 | } 671 | .thumbnails { 672 | margin-left: -30px; 673 | } 674 | .thumbnails > li { 675 | margin-left: 30px; 676 | } 677 | .row-fluid .thumbnails { 678 | margin-left: 0; 679 | } 680 | } 681 | 682 | @media (max-width: 979px) { 683 | body { 684 | padding-top: 0; 685 | } 686 | .navbar-fixed-top, 687 | .navbar-fixed-bottom { 688 | position: static; 689 | } 690 | .navbar-fixed-top { 691 | margin-bottom: 18px; 692 | } 693 | .navbar-fixed-bottom { 694 | margin-top: 18px; 695 | } 696 | .navbar-fixed-top .navbar-inner, 697 | .navbar-fixed-bottom .navbar-inner { 698 | padding: 5px; 699 | } 700 | .navbar .container { 701 | width: auto; 702 | padding: 0; 703 | } 704 | .navbar .brand { 705 | padding-right: 10px; 706 | padding-left: 10px; 707 | margin: 0 0 0 -5px; 708 | } 709 | .nav-collapse { 710 | clear: both; 711 | } 712 | .nav-collapse .nav { 713 | float: none; 714 | margin: 0 0 9px; 715 | } 716 | .nav-collapse .nav > li { 717 | float: none; 718 | } 719 | .nav-collapse .nav > li > a { 720 | margin-bottom: 2px; 721 | } 722 | .nav-collapse .nav > .divider-vertical { 723 | display: none; 724 | } 725 | .nav-collapse .nav .nav-header { 726 | color: #999999; 727 | text-shadow: none; 728 | } 729 | .nav-collapse .nav > li > a, 730 | .nav-collapse .dropdown-menu a { 731 | padding: 6px 15px; 732 | font-weight: bold; 733 | color: #999999; 734 | -webkit-border-radius: 3px; 735 | -moz-border-radius: 3px; 736 | border-radius: 3px; 737 | } 738 | .nav-collapse .btn { 739 | padding: 4px 10px 4px; 740 | font-weight: normal; 741 | -webkit-border-radius: 4px; 742 | -moz-border-radius: 4px; 743 | border-radius: 4px; 744 | } 745 | .nav-collapse .dropdown-menu li + li a { 746 | margin-bottom: 2px; 747 | } 748 | .nav-collapse .nav > li > a:hover, 749 | .nav-collapse .dropdown-menu a:hover { 750 | background-color: #222222; 751 | } 752 | .nav-collapse.in .btn-group { 753 | padding: 0; 754 | margin-top: 5px; 755 | } 756 | .nav-collapse .dropdown-menu { 757 | position: static; 758 | top: auto; 759 | left: auto; 760 | display: block; 761 | float: none; 762 | max-width: none; 763 | padding: 0; 764 | margin: 0 15px; 765 | background-color: transparent; 766 | border: none; 767 | -webkit-border-radius: 0; 768 | -moz-border-radius: 0; 769 | border-radius: 0; 770 | -webkit-box-shadow: none; 771 | -moz-box-shadow: none; 772 | box-shadow: none; 773 | } 774 | .nav-collapse .dropdown-menu:before, 775 | .nav-collapse .dropdown-menu:after { 776 | display: none; 777 | } 778 | .nav-collapse .dropdown-menu .divider { 779 | display: none; 780 | } 781 | .nav-collapse .navbar-form, 782 | .nav-collapse .navbar-search { 783 | float: none; 784 | padding: 9px 15px; 785 | margin: 9px 0; 786 | border-top: 1px solid #222222; 787 | border-bottom: 1px solid #222222; 788 | -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1); 789 | -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1); 790 | box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1); 791 | } 792 | .navbar .nav-collapse .nav.pull-right { 793 | float: none; 794 | margin-left: 0; 795 | } 796 | .nav-collapse, 797 | .nav-collapse.collapse { 798 | height: 0; 799 | overflow: hidden; 800 | } 801 | .navbar .btn-navbar { 802 | display: block; 803 | } 804 | .navbar-static .navbar-inner { 805 | padding-right: 10px; 806 | padding-left: 10px; 807 | } 808 | } 809 | 810 | @media (min-width: 980px) { 811 | .nav-collapse.collapse { 812 | height: auto !important; 813 | overflow: visible !important; 814 | } 815 | } 816 | -------------------------------------------------------------------------------- /js/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap.js by @fat & @mdo 3 | * Copyright 2012 Twitter, Inc. 4 | * http://www.apache.org/licenses/LICENSE-2.0.txt 5 | */ 6 | !function(a){a(function(){"use strict",a.support.transition=function(){var a=function(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd",msTransition:"MSTransitionEnd",transition:"transitionend"},c;for(c in b)if(a.style[c]!==undefined)return b[c]}();return a&&{end:a}}()})}(window.jQuery),!function(a){"use strict";var b='[data-dismiss="alert"]',c=function(c){a(c).on("click",b,this.close)};c.prototype.close=function(b){function f(){e.trigger("closed").remove()}var c=a(this),d=c.attr("data-target"),e;d||(d=c.attr("href"),d=d&&d.replace(/.*(?=#[^\s]*$)/,"")),e=a(d),b&&b.preventDefault(),e.length||(e=c.hasClass("alert")?c:c.parent()),e.trigger(b=a.Event("close"));if(b.isDefaultPrevented())return;e.removeClass("in"),a.support.transition&&e.hasClass("fade")?e.on(a.support.transition.end,f):f()},a.fn.alert=function(b){return this.each(function(){var d=a(this),e=d.data("alert");e||d.data("alert",e=new c(this)),typeof b=="string"&&e[b].call(d)})},a.fn.alert.Constructor=c,a(function(){a("body").on("click.alert.data-api",b,c.prototype.close)})}(window.jQuery),!function(a){"use strict";var b=function(b,c){this.$element=a(b),this.options=a.extend({},a.fn.button.defaults,c)};b.prototype.setState=function(a){var b="disabled",c=this.$element,d=c.data(),e=c.is("input")?"val":"html";a+="Text",d.resetText||c.data("resetText",c[e]()),c[e](d[a]||this.options[a]),setTimeout(function(){a=="loadingText"?c.addClass(b).attr(b,b):c.removeClass(b).removeAttr(b)},0)},b.prototype.toggle=function(){var a=this.$element.parent('[data-toggle="buttons-radio"]');a&&a.find(".active").removeClass("active"),this.$element.toggleClass("active")},a.fn.button=function(c){return this.each(function(){var d=a(this),e=d.data("button"),f=typeof c=="object"&&c;e||d.data("button",e=new b(this,f)),c=="toggle"?e.toggle():c&&e.setState(c)})},a.fn.button.defaults={loadingText:"loading..."},a.fn.button.Constructor=b,a(function(){a("body").on("click.button.data-api","[data-toggle^=button]",function(b){var c=a(b.target);c.hasClass("btn")||(c=c.closest(".btn")),c.button("toggle")})})}(window.jQuery),!function(a){"use strict";var b=function(b,c){this.$element=a(b),this.options=c,this.options.slide&&this.slide(this.options.slide),this.options.pause=="hover"&&this.$element.on("mouseenter",a.proxy(this.pause,this)).on("mouseleave",a.proxy(this.cycle,this))};b.prototype={cycle:function(b){return b||(this.paused=!1),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},to:function(b){var c=this.$element.find(".active"),d=c.parent().children(),e=d.index(c),f=this;if(b>d.length-1||b<0)return;return this.sliding?this.$element.one("slid",function(){f.to(b)}):e==b?this.pause().cycle():this.slide(b>e?"next":"prev",a(d[b]))},pause:function(a){return a||(this.paused=!0),clearInterval(this.interval),this.interval=null,this},next:function(){if(this.sliding)return;return this.slide("next")},prev:function(){if(this.sliding)return;return this.slide("prev")},slide:function(b,c){var d=this.$element.find(".active"),e=c||d[b](),f=this.interval,g=b=="next"?"left":"right",h=b=="next"?"first":"last",i=this,j=a.Event("slide");this.sliding=!0,f&&this.pause(),e=e.length?e:this.$element.find(".item")[h]();if(e.hasClass("active"))return;if(a.support.transition&&this.$element.hasClass("slide")){this.$element.trigger(j);if(j.isDefaultPrevented())return;e.addClass(b),e[0].offsetWidth,d.addClass(g),e.addClass(g),this.$element.one(a.support.transition.end,function(){e.removeClass([b,g].join(" ")).addClass("active"),d.removeClass(["active",g].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger("slid")},0)})}else{this.$element.trigger(j);if(j.isDefaultPrevented())return;d.removeClass("active"),e.addClass("active"),this.sliding=!1,this.$element.trigger("slid")}return f&&this.cycle(),this}},a.fn.carousel=function(c){return this.each(function(){var d=a(this),e=d.data("carousel"),f=a.extend({},a.fn.carousel.defaults,typeof c=="object"&&c);e||d.data("carousel",e=new b(this,f)),typeof c=="number"?e.to(c):typeof c=="string"||(c=f.slide)?e[c]():f.interval&&e.cycle()})},a.fn.carousel.defaults={interval:5e3,pause:"hover"},a.fn.carousel.Constructor=b,a(function(){a("body").on("click.carousel.data-api","[data-slide]",function(b){var c=a(this),d,e=a(c.attr("data-target")||(d=c.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,"")),f=!e.data("modal")&&a.extend({},e.data(),c.data());e.carousel(f),b.preventDefault()})})}(window.jQuery),!function(a){"use strict";var b=function(b,c){this.$element=a(b),this.options=a.extend({},a.fn.collapse.defaults,c),this.options.parent&&(this.$parent=a(this.options.parent)),this.options.toggle&&this.toggle()};b.prototype={constructor:b,dimension:function(){var a=this.$element.hasClass("width");return a?"width":"height"},show:function(){var b,c,d,e;if(this.transitioning)return;b=this.dimension(),c=a.camelCase(["scroll",b].join("-")),d=this.$parent&&this.$parent.find("> .accordion-group > .in");if(d&&d.length){e=d.data("collapse");if(e&&e.transitioning)return;d.collapse("hide"),e||d.data("collapse",null)}this.$element[b](0),this.transition("addClass",a.Event("show"),"shown"),this.$element[b](this.$element[0][c])},hide:function(){var b;if(this.transitioning)return;b=this.dimension(),this.reset(this.$element[b]()),this.transition("removeClass",a.Event("hide"),"hidden"),this.$element[b](0)},reset:function(a){var b=this.dimension();return this.$element.removeClass("collapse")[b](a||"auto")[0].offsetWidth,this.$element[a!==null?"addClass":"removeClass"]("collapse"),this},transition:function(b,c,d){var e=this,f=function(){c.type=="show"&&e.reset(),e.transitioning=0,e.$element.trigger(d)};this.$element.trigger(c);if(c.isDefaultPrevented())return;this.transitioning=1,this.$element[b]("in"),a.support.transition&&this.$element.hasClass("collapse")?this.$element.one(a.support.transition.end,f):f()},toggle:function(){this[this.$element.hasClass("in")?"hide":"show"]()}},a.fn.collapse=function(c){return this.each(function(){var d=a(this),e=d.data("collapse"),f=typeof c=="object"&&c;e||d.data("collapse",e=new b(this,f)),typeof c=="string"&&e[c]()})},a.fn.collapse.defaults={toggle:!0},a.fn.collapse.Constructor=b,a(function(){a("body").on("click.collapse.data-api","[data-toggle=collapse]",function(b){var c=a(this),d,e=c.attr("data-target")||b.preventDefault()||(d=c.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,""),f=a(e).data("collapse")?"toggle":c.data();a(e).collapse(f)})})}(window.jQuery),!function(a){function d(){a(b).parent().removeClass("open")}"use strict";var b='[data-toggle="dropdown"]',c=function(b){var c=a(b).on("click.dropdown.data-api",this.toggle);a("html").on("click.dropdown.data-api",function(){c.parent().removeClass("open")})};c.prototype={constructor:c,toggle:function(b){var c=a(this),e,f,g;if(c.is(".disabled, :disabled"))return;return f=c.attr("data-target"),f||(f=c.attr("href"),f=f&&f.replace(/.*(?=#[^\s]*$)/,"")),e=a(f),e.length||(e=c.parent()),g=e.hasClass("open"),d(),g||e.toggleClass("open"),!1}},a.fn.dropdown=function(b){return this.each(function(){var d=a(this),e=d.data("dropdown");e||d.data("dropdown",e=new c(this)),typeof b=="string"&&e[b].call(d)})},a.fn.dropdown.Constructor=c,a(function(){a("html").on("click.dropdown.data-api",d),a("body").on("click.dropdown",".dropdown form",function(a){a.stopPropagation()}).on("click.dropdown.data-api",b,c.prototype.toggle)})}(window.jQuery),!function(a){function c(){var b=this,c=setTimeout(function(){b.$element.off(a.support.transition.end),d.call(b)},500);this.$element.one(a.support.transition.end,function(){clearTimeout(c),d.call(b)})}function d(a){this.$element.hide().trigger("hidden"),e.call(this)}function e(b){var c=this,d=this.$element.hasClass("fade")?"fade":"";if(this.isShown&&this.options.backdrop){var e=a.support.transition&&d;this.$backdrop=a('