Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #632 from ExactTarget/default-dropdown-header
Browse files Browse the repository at this point in the history
default-dropdown-header: selectlist: make default have <a>
  • Loading branch information
Kevin Parkerson committed Aug 29, 2014
2 parents 38f345d + 217fdb1 commit e157e74
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
24 changes: 23 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ <h5>Sample Methods</h5>
<h2 id="selectlist"><a href="#selectlist">#</a>Selectlist</h2>

<div class="form-group">
<label class="control-label" for="MySelectlistHiddenInput">With auto-resize</label>
<label class="control-label" for="MySelectlistHiddenInput">Default With auto-resize</label>
<div class="input-group">

<div id="MySelectlist" class="btn-group selectlist" data-initialize="selectlist" data-resize="auto">
Expand All @@ -1539,6 +1539,28 @@ <h2 id="selectlist"><a href="#selectlist">#</a>Selectlist</h2>

</div>

<div class="form-group">
<label class="control-label" for="MySelectlistNoDefaultInput">No default</label>
<div class="input-group">

<div id="MySelectlistNoDefault" class="btn-group selectlist" data-initialize="selectlist" data-resize="auto">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="selected-label"></span>
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li class="dropdown-header">Heading 1</li>
<li data-value="1"><a href="#">One</a></li>
<li data-value="2"><a href="#">Two</a></li>
<li class="dropdown-header">Heading 2</li>
<li data-value="3"><a href="#">Three</a></li>
<li data-value="4" data-foo="bar" data-fizz="buzz"><a href="#">Buzz</a></li>
<li data-value="Item Five"><a href="#">Item Five</a></li>
</ul>
<input id="MySelectlistNoDefaultInput" class="hidden hidden-field" name="MySelectlist" readonly="readonly" aria-hidden="true" type="text"/>
</div>

</div>

<div class="form-group">
Expand Down
15 changes: 6 additions & 9 deletions js/selectlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,13 @@
},

setDefaultSelection: function() {
var selector = 'li[data-selected=true]:first';
var item = this.$element.find(selector);
if(item.length === 0) {
// select first item
this.selectByIndex(0);
}
else {
// select by data-attribute
this.selectBySelector(selector);
var $item = this.$element.find('li[data-selected=true]').eq(0);

if($item.length === 0) {
$item = this.$element.find('li').has('a').eq(0);
}

this.doSelect($item);
},

enable: function() {
Expand Down

0 comments on commit e157e74

Please sign in to comment.