Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError when Search plugin disabled #675

Closed
ghost opened this issue Jan 22, 2018 · 5 comments
Closed

Uncaught ReferenceError when Search plugin disabled #675

ghost opened this issue Jan 22, 2018 · 5 comments
Assignees
Labels
bug Issue reports a bug

Comments

@ghost
Copy link

ghost commented Jan 22, 2018

Description

When plugins are removed, loading a page signals an Uncaught ReferenceError.

Expected behavior

No error message.

Actual behavior

Uncaught ReferenceError
    at new t (application.ed2cc613.js:1)
    at Object.i [as initialize] (application.ed2cc613.js:1)
    at (index):292

Steps to reproduce the bug

  1. Initialise new MkDocs instance
  2. Edit mkdocs.yml:
site_name: MyDocs
plugins: []
  1. Observe expected behaviour

  2. Edit mkdocs.yml:

site_name: MyDocs
plugins: []
theme: 
  name: 'material'
  1. Observe actual behaviour

Package versions

  • Python: 2.7.10
  • MkDocs: 0.17.2
  • Material: 2.5.1

Project configuration

site_name: MyDocs
plugins: []
theme: 
  name: 'material'

System information

  • OS: macOS 10.13.2
  • Browser: Observed on Chrome, Safari and IE11.

Consequences

No consequences observed on Chrome or Safari.

On Internet Explorer 11 our theme.js does not run:

/*
 * Custom script for code.kx.com/q 
 * Author: stephen@kx.com
 * Version: 2018.01.17
 * https://gist.github.com/wpscholar/4637176#file-jquery-external-links-new-window-js-L4
 * Open all external links in a new window
 */
$(function() {
    $('a').not('[href*="mailto:"]').each(function () {
		var isInternalLink = new RegExp('/' + window.location.host + '/');
		if ( ! isInternalLink.test(this.href) ) {
			$(this).attr('target', '_blank');
		}
	});
	// Custom Search box
	// copy of HTML generated by native Search plugin 
	var html=`
    <label class="md-icon md-icon--search md-header-nav__button" for="search"></label>

    <div class="md-search" data-md-component="search" role="dialog">
      <label class="md-search__overlay" for="search"></label>
      <div class="md-search__inner">
        <form class="md-search__form" id="kx-search-form" name="search">
          <input type="text" class="md-search__input" id="kx-search-query" name="query" required placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
          <label class="md-icon md-search__icon" for="search"></label>
          <button type="reset" class="md-icon md-search__icon" data-md-component="reset">&#xE5CD;</button>
        </form>
        <div class="md-search__output">
          <div class="md-search__scrollwrap" data-md-scrollfix>
            <div class="md-search-result" data-md-component="result">
              <div class="md-search-result__meta">
                Type a query and hit Enter
              </div>
              <div class="md-search-result__list"/>
            </div>
          </div>
        </div>
      </div>
    </div>
	`;
	$("div.md-flex div").last().append(html);
	var serviceRoot = 'https://code.kx.com/q/search'; // >>> reverse-proxy directive on Apache httpd
	var srchHandler =function( evt ) {
		// console.log(evt.which);
		if( evt.which===13 ) {
			var url = serviceRoot + "?query=" + encodeURIComponent($("#kx-search-query").val());
			console.log(url);
			window.location = url;
/*          // This query might be executed from a page called by HTTPS, so url below can only be an HTTPS call
			$.get(url, function( data ) {
				alert( 'ping!' );
				console.log( data );
				$( ".md-search-result__list" ).html( data );
			});
*/			return false;
		};
	};
	$("#kx-search-form").keypress(srchHandler);
});
@squidfunk
Copy link
Owner

Thanks for reporting. Search is actually implemented as a plugin from MkDocs 0.17.0 on, so the search will not work, that's correct. However, the ReferenceError is indeed an error. The JavaScript must intercept search not being present. Will provide a fix.

@squidfunk squidfunk self-assigned this Jan 22, 2018
@squidfunk squidfunk added the bug Issue reports a bug label Jan 22, 2018
@squidfunk
Copy link
Owner

Fixed in #676.

@squidfunk
Copy link
Owner

Released as part of 2.5.2.

@ghost
Copy link
Author

ghost commented Jan 23, 2018

Thanks for the fast fix. My theme.js now OK in IE11.

@linuxiamo
Copy link

linuxiamo commented Oct 1, 2018

Hi,
I have a different error in the browser console that prevents the search to work.

It states:
Uncaught (in promise) SyntaxError: Unexpected token t in JSON at position 16901

I have an old copy of the documentation I was writing and at that stage I had no problems.

In my ignorance of the matter, I did a comparison between the files in the old directory and the ones in the new folder. It seems to me that the only thing changed - apart from document - is the search_index.json file.

Do you think the problem could be in this file? Is there a way to regenerate it?
Thanks for the help and for the great theme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug
Projects
None yet
Development

No branches or pull requests

2 participants