-
Notifications
You must be signed in to change notification settings - Fork 610
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
allow users to create their own wrappers #16743
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,10 +39,12 @@ var _ = function (input, o) { | |
|
||
// Create necessary elements | ||
|
||
this.container = $.create("div", { | ||
className: "awesomplete", | ||
around: input | ||
}); | ||
this.container = input.parentNode.className.search(/awesomplete-wrapper/) >= 0 ? | ||
input.parentNode : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for a ternary here. You can just do something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. help |
||
$.create("div", { | ||
className: "awesomplete-wrapper", | ||
around: input | ||
}); | ||
|
||
this.ul = $.create("ul", { | ||
hidden: "", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,15 @@ <h1>Basic usage</h1> | |
<p>Before you try anything, you need to include <code>awesomplete.css</code> and <code>awesomplete.js</code> in your page, via the usual <code><link rel="stylesheet" href="awesomplete.css" /></code> and <code><script src="awesomplete.js" async></script></code> tags.</p> | ||
|
||
<p>For the autocomplete, you just need an <code><input></code> text field (might work on <code><textarea></code> and elements with <code>contentEditable</code>, but that hasn’t been tested). Add <code>class="awesomplete"</code> for it to be <strong>automatically processed</strong> (you can still specify many options via HTML attributes), otherwise you can instantiate with a few lines of JS code, which allow for more customization.</p> | ||
|
||
<p><strong>Note:</strong> Awesomplete will wrap your input in a div with the class 'awesomplete-wrapper'. If other elements need to stay with your input, such as a label, you can simply make the wrapper yourself and Awesomplete will pick it up: | ||
|
||
<pre class="language-markup"><code><div class="awesomplete-wrapper"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to show an actual label here, not another div. |
||
<input class="awesomplete" | ||
data-list="Ada, Java, JavaScript, Brainfuck, LOLCODE, Node.js, Ruby on Rails" /> | ||
<label>My label</label> | ||
<div></code></pre> | ||
|
||
<p>There are many ways <strong>to link an input to a list of suggestions</strong>. The simple example above could have also been made with the following markup, which provides a nice native fallback in case the script doesn’t load:</p> | ||
|
||
<pre class="language-markup"><code><input class="awesomplete" list="mylist" /> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not
classList.contains("awesomplete-wrapper")
?(if the answer is "browser support", IE9 can go fu…erm use a polyfill)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's why. Carries no real cost, so might as well.