function watch_autocomplete() {
    	if (typeof(editor.completer) === "undefined") {
    		return;
    	}

    	var prev = editor.autocomplete_selection;
    	var res = editor.completer.popup.getRow();
    	editor.autocomplete_selection = undefined;
    	if (res >= 0) {
    		if (editor.completer.completions) {
    			editor.autocomplete_selection_index = res;
    			editor.autocomplete_selection = editor.completer.completions.filtered[res];
			}
		}

		if (prev !== editor.autocomplete_selection) { //selection changed
			$('.autocomplete-tooltip').remove(); //remove prev tooltip
			if (editor.autocomplete_selection) {
				var a = editor.autocomplete_selection;

				var title = a.name || a.caption || a.value;
				$('body').append('<div class="autocomplete-tooltip"><h3>' + title + '</h3><div class="content"><span class="loading"></span></div></div>');
				$('.autocomplete-tooltip').css('left', $('.ace_autocomplete').offset().left - $(document).scrollLeft() + $('.ace_autocomplete').width() + 5);
				$('.autocomplete-tooltip').css('top', $('.ace_autocomplete').offset().top - $(document).scrollTop() + editor.autocomplete_selection_index*16);

				var info = "<p>No info found.</p>";
				var callback = function(data) {
					//check if selection has changed
					var a = editor.autocomplete_selection;
					var new_title = a.name || a.caption || a.value;
					if (title != new_title) return;

					info = data;
					$('.autocomplete-tooltip > .content').html(info);

					//apply formatting
					var pre_list = $('.autocomplete-tooltip pre');
					for (var i=0; i<pre_list.length; i++) {
						var text = $(pre_list[i]).text();
						$(pre_list[i]).text(decodeURIComponent(text));
					}
				};

				var info_url = '';
				if (a.meta == "local") { //local variables
					$('.autocomplete-tooltip > .content').html('<p>Local term.</p>');
				}
				else { //everything else
					if (a.meta == "SPARQL Core") { //core
						info_url = '/query-designer/docs/sparql/' + a.value + '/'
					} else {
						info_url = '/query-designer/docs/' + editor.recommendation + '/';
						if (editor.recommendation_from !== "") {
							info_url += encodeURIComponent(editor.recommendation_from) + '/'
						}
						info_url += '?q=' + encodeURIComponent(editor.autocomplete_selection.full_uri);
					}

					//get the info from server
					info = $.ajax({url: info_url}).then(callback, function() {
						$('.autocomplete-tooltip > .content').append('<p>No info found.</p>');
					});
				}
			}
		}
    }
/*Check if autocomplete selection has changed*/
Check if autocomplete selection has changed
Check if autocomplete selection has changed
function watch_autocomplete() {
    	if (typeof(editor.completer) === "undefined") {
    		return;
    	}
    	var prev = editor.autocomplete_selection;
    	var res = editor.completer.popup.getRow();
    	editor.autocomplete_selection = undefined;
    	if (res >= 0) {
    		if (editor.completer.completions) {
    			editor.autocomplete_selection_index = res;
    			editor.autocomplete_selection = editor.completer.completions.filtered[res];
			}
		}
		if (prev !== editor.autocomplete_selection) { 
			$('.autocomplete-tooltip').remove(); 
			if (editor.autocomplete_selection) {
				var a = editor.autocomplete_selection;
				var title = a.name || a.caption || a.value;
				$('body').append('<div class="autocomplete-tooltip"><h3>' + title + '</h3><div class="content"><span class="loading"></span></div></div>');
				$('.autocomplete-tooltip').css('left', $('.ace_autocomplete').offset().left - $(document).scrollLeft() + $('.ace_autocomplete').width() + 5);
				$('.autocomplete-tooltip').css('top', $('.ace_autocomplete').offset().top - $(document).scrollTop() + editor.autocomplete_selection_index*16);
				var info = "<p>No info found.</p>";
				var callback = function(data) {
					var a = editor.autocomplete_selection;
					var new_title = a.name || a.caption || a.value;
					if (title != new_title) return;
					info = data;
					$('.autocomplete-tooltip > .content').html(info);
					var pre_list = $('.autocomplete-tooltip pre');
					for (var i=0; i<pre_list.length; i++) {
						var text = $(pre_list[i]).text();
						$(pre_list[i]).text(decodeURIComponent(text));
					}
				};
				var info_url = '';
				if (a.meta == "local") { 
					$('.autocomplete-tooltip > .content').html('<p>Local term.</p>');
				}
				else { 
					if (a.meta == "SPARQL Core") { 
						info_url = '/query-designer/docs/sparql/' + a.value + '/'
					} else {
						info_url = '/query-designer/docs/' + editor.recommendation + '/';
						if (editor.recommendation_from !== "") {
							info_url += encodeURIComponent(editor.recommendation_from) + '/'
						}
						info_url += '?q=' + encodeURIComponent(editor.autocomplete_selection.full_uri);
					}
					info = $.ajax({url: info_url}).then(callback, function() {
						$('.autocomplete-tooltip > .content').append('<p>No info found.</p>');
					});
				}
			}
		}
    }
function watch_autocomplete ( ) { if ( typeof ( editor . completer ) === "undefined" ) { return ; } var prev = editor . autocomplete_selection ; var res = editor . completer . popup . getRow ( ) ; editor . autocomplete_selection = undefined ; if ( res >= 0 ) { if ( editor . completer . completions ) { editor . autocomplete_selection_index = res ; editor . autocomplete_selection = editor . completer . completions . filtered [ res ] ; } } if ( prev !== editor . autocomplete_selection ) { $ ( '.autocomplete-tooltip' ) . remove ( ) ; if ( editor . autocomplete_selection ) { var a = editor . autocomplete_selection ; var title = a . name || a . caption || a . value ; $ ( 'body' ) . append ( '<div class="autocomplete-tooltip"><h3>' + title + '</h3><div class="content"><span class="loading"></span></div></div>' ) ; $ ( '.autocomplete-tooltip' ) . css ( 'left' , $ ( '.ace_autocomplete' ) . offset ( ) . left - $ ( document ) . scrollLeft ( ) + $ ( '.ace_autocomplete' ) . width ( ) + 5 ) ; $ ( '.autocomplete-tooltip' ) . css ( 'top' , $ ( '.ace_autocomplete' ) . offset ( ) . top - $ ( document ) . scrollTop ( ) + editor . autocomplete_selection_index * 16 ) ; var info = "<p>No info found.</p>" ; var callback = function ( data ) { var a = editor . autocomplete_selection ; var new_title = a . name || a . caption || a . value ; if ( title != new_title ) return ; info = data ; $ ( '.autocomplete-tooltip > .content' ) . html ( info ) ; var pre_list = $ ( '.autocomplete-tooltip pre' ) ; for ( var i = 0 ; i < pre_list . length ; i ++ ) { var text = $ ( pre_list [ i ] ) . text ( ) ; $ ( pre_list [ i ] ) . text ( decodeURIComponent ( text ) ) ; } } ; var info_url = '' ; if ( a . meta == "local" ) { $ ( '.autocomplete-tooltip > .content' ) . html ( '<p>Local term.</p>' ) ; } else { if ( a . meta == "SPARQL Core" ) { info_url = '/query-designer/docs/sparql/' + a . value + '/' } else { info_url = '/query-designer/docs/' + editor . recommendation + '/' ; if ( editor . recommendation_from !== "" ) { info_url += encodeURIComponent ( editor . recommendation_from ) + '/' } info_url += '?q=' + encodeURIComponent ( editor . autocomplete_selection . full_uri ) ; } info = $ . ajax ( { url : info_url } ) . then ( callback , function ( ) { $ ( '.autocomplete-tooltip > .content' ) . append ( '<p>No info found.</p>' ) ; } ) ; } } } }
Check if autocomplete selection has changed
Check if autocomplete selection has changed
//selection changed //remove prev tooltip //check if selection has changed //apply formatting //local variables //everything else //core //get the info from server