5 // Wykonuje block z zaĆadowanymi kanonicznymi motywami
6 $.themes.withCanon = function(code_block, onError) {
7 if (typeof $.themes.canon == 'undefined') {
11 success: function(data) {
12 $.themes.canon = data.split('\n');
13 code_block($.themes.canon);
16 $.themes.canon = null;
17 code_block($.themes.canon);
22 code_block($.themes.canon);
26 function split( val ) {
27 return val.split( /,\s*/ );
29 function extractLast( term ) {
30 return split( term ).pop();
33 $.themes.autocomplete = function(elem) {
35 source: function(request, response) {
36 var query = extractLast(request.term).toLowerCase();
37 $.themes.withCanon(function(canonThemes) {
39 $.each(canonThemes, function(i, theme) {
40 if (theme.toLowerCase().startsWith(query)) {
41 candidates.push(theme);
43 if (candidates.length == 10) {
51 var term = extractLast( this.value );
52 if ( term.length < 1 ) {
57 // prevent value inserted on focus
60 select: function( event, ui ) {
61 var terms = split( this.value );
63 terms.push( ui.item.value );
65 this.value = terms.join( ", " );
68 appendTo: elem.parent()