Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separated widget module from initialization
moving widget functionality to separate file required adding a new module which assumes responsibility for initialization ("glue code"), since that doesn't happen automatically anymore (cf. previous commit; e74be2e)
- Loading branch information
Showing
4 changed files
with
33 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(function($) { | ||
|
||
"use strict"; | ||
|
||
window.createFilterWidget = function(contactList) { | ||
$('<input type="search" />').insertBefore(contactList). | ||
on("keyup", onFilter); | ||
} | ||
|
||
function onFilter(ev) { | ||
var filterField = $(this); | ||
var contacts = filterField.next(); | ||
var input = filterField.val(); | ||
|
||
var names = contacts.find("li .p-name"); | ||
names.each(function(i, node) { | ||
var el = $(node); | ||
var name = el.text(); | ||
|
||
var match = name.indexOf(input) === 0; | ||
var container = el.closest(".h-card"); | ||
if(match) { | ||
container.slideDown(); | ||
} else { | ||
container.slideUp(); | ||
} | ||
}); | ||
} | ||
|
||
}(jQuery)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1 @@ | ||
(function($) { | ||
|
||
"use strict"; | ||
|
||
window.createFilterWidget = function(contactList) { | ||
$('<input type="search" />').insertBefore(contactList). | ||
on("keyup", onFilter); | ||
} | ||
|
||
function onFilter(ev) { | ||
var filterField = $(this); | ||
var contacts = filterField.next(); | ||
var input = filterField.val(); | ||
|
||
var names = contacts.find("li .p-name"); | ||
names.each(function(i, node) { | ||
var el = $(node); | ||
var name = el.text(); | ||
|
||
var match = name.indexOf(input) === 0; | ||
var container = el.closest(".h-card"); | ||
if(match) { | ||
container.slideDown(); | ||
} else { | ||
container.slideUp(); | ||
} | ||
}); | ||
} | ||
|
||
}(jQuery)); | ||
createFilterWidget(jQuery("ul.contacts")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters