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

Add some fetures. #201

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 33 additions & 11 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,18 @@ var EasyAutocomplete = (function(scope) {
var animationTime = config.get("list").showAnimation.time,
callback = config.get("list").showAnimation.callback;

$elements_container.find("ul").slideDown(animationTime, callback);
$elements_container.slideDown(animationTime, callback);
break;

case "fade":
var animationTime = config.get("list").showAnimation.time,
callback = config.get("list").showAnimation.callback;

$elements_container.find("ul").fadeIn(animationTime), callback;
$elements_container.fadeIn(animationTime), callback;
break;

default:
$elements_container.find("ul").show();
$elements_container.show();
break;
}

Expand All @@ -218,18 +218,18 @@ var EasyAutocomplete = (function(scope) {
var animationTime = config.get("list").hideAnimation.time,
callback = config.get("list").hideAnimation.callback;

$elements_container.find("ul").slideUp(animationTime, callback);
$elements_container.slideUp(animationTime, callback);
break;

case "fade":
var animationTime = config.get("list").hideAnimation.time,
callback = config.get("list").hideAnimation.callback;

$elements_container.find("ul").fadeOut(animationTime, callback);
$elements_container.fadeOut(animationTime, callback);
break;

default:
$elements_container.find("ul").hide();
$elements_container.hide();
break;
}

Expand All @@ -242,6 +242,11 @@ var EasyAutocomplete = (function(scope) {

config.get("list").onSelectItemEvent();
})
.on("hoverElement.eac", function() {
$elements_container.find("ul li").removeClass("hover");
$elements_container.find("ul li").eq(hoveredElement).addClass("hover");
//config.get("list").onSelectItemEvent();
})
.on("loadElements.eac", function(event, listBuilders, phrase) {


Expand Down Expand Up @@ -289,9 +294,8 @@ var EasyAutocomplete = (function(scope) {
config.get("list").onChooseEvent();
})
.mouseover(function() {

selectedElement = itemCounter;
selectElement(itemCounter);
hoveredElement = itemCounter;
hoverElement(itemCounter);

config.get("list").onMouseOverEvent();
})
Expand Down Expand Up @@ -363,7 +367,9 @@ var EasyAutocomplete = (function(scope) {
function bindEvents() {

bindAllEvents();

//To load at first time
loadData("");
hideContainer();
//------------------------ FUNCTIONS --------------------------


Expand All @@ -378,6 +384,7 @@ var EasyAutocomplete = (function(scope) {
bindKeypress();
bindFocus();
bindBlur();
bindMouseDown();
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -462,7 +469,8 @@ var EasyAutocomplete = (function(scope) {

default:

if (event.keyCode > 40 || event.keyCode === 8) {
// code 32 for support when ending typing chinese with space key
if (event.keyCode > 40 || event.keyCode === 8 || event.keyCode === 32) {

var inputPhrase = $field.val();

Expand Down Expand Up @@ -668,6 +676,15 @@ var EasyAutocomplete = (function(scope) {
});
}

function bindMouseDown() {
$field.mousedown(function() {
setTimeout(function() {
selectedElement = -1;
showContainer();
}, 250);
});
}

function removeAutocomplete() {
$field.attr("autocomplete","off");
}
Expand Down Expand Up @@ -695,6 +712,11 @@ var EasyAutocomplete = (function(scope) {
$container.trigger("selectElement.eac", index);
}

function hoverElement(index) {

$container.trigger("hoverElement.eac", index);
}

function loadElements(list, phrase) {
$container.trigger("loadElements.eac", [list, phrase]);
}
Expand Down
15 changes: 13 additions & 2 deletions src/sass/easy-autocomplete.scss
Original file line number Diff line number Diff line change
Expand Up @@ -365,17 +365,20 @@ $purple: #c7c0de;
position: absolute;
width: 100%;
z-index: 2;

//to limit the height when there is many result show in the container
height: 223px;
overflow: auto;
ul {
background: none repeat scroll 0 0 #ffffff;
border-top: 1px dotted #ccc;
display: none;
//display: none;
margin-top: 0;
padding-bottom: 0;
padding-left: 0;
position: relative;
top: -1px;


li, .eac-category {
background: inherit;
border: {
Expand Down Expand Up @@ -409,6 +412,14 @@ $purple: #c7c0de;
font-weight: normal;
}
}
&.hover{
background: none repeat scroll 0 0 rgba(158, 158, 158, 0.48);
cursor: pointer;

div {
font-weight: normal;
}
}

div {
display: block;
Expand Down