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

Adds noResults option #215

Open
wants to merge 1 commit 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
45 changes: 23 additions & 22 deletions src/configuration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* EasyAutocomplete - Configuration
* EasyAutocomplete - Configuration
*/
var EasyAutocomplete = (function(scope){

Expand Down Expand Up @@ -81,7 +81,7 @@ var EasyAutocomplete = (function(scope){
onChooseEvent: function() {},
onKeyEnterEvent: function() {},
onMouseOverEvent: function() {},
onMouseOutEvent: function() {},
onMouseOutEvent: function() {},
onShowListEvent: function() {},
onHideListEvent: function() {}
},
Expand All @@ -98,6 +98,8 @@ var EasyAutocomplete = (function(scope){

adjustWidth: true,

noResults: false,

ajaxSettings: {},

preparePostData: function(data, inputPhrase) {return data;},
Expand All @@ -114,7 +116,7 @@ var EasyAutocomplete = (function(scope){
}]

};

var externalObjects = ["ajaxSettings", "template"];

this.get = function(propertyName) {
Expand All @@ -126,8 +128,8 @@ var EasyAutocomplete = (function(scope){
if (defaults[name] === value) {
return true;
}
}
}

return false;
};

Expand Down Expand Up @@ -159,7 +161,7 @@ var EasyAutocomplete = (function(scope){
mergeOptions();

if (defaults.loggerEnabled === true) {
printPropertiesThatDoesntExist(console, options);
printPropertiesThatDoesntExist(console, options);
}

addAjaxSettings();
Expand All @@ -174,19 +176,19 @@ var EasyAutocomplete = (function(scope){
function prepareDefaults() {

if (options.dataType === "xml") {

if (!options.getValue) {

options.getValue = function(element) {
return $(element).text();
};
}


if (!options.list) {

options.list = {};
}
}

if (!options.list.sort) {
options.list.sort = {};
Expand All @@ -196,7 +198,7 @@ var EasyAutocomplete = (function(scope){
options.list.sort.method = function(a, b) {
a = options.getValue(a);
b = options.getValue(b);

//Alphabeticall sort
if (a < b) {
return -1;
Expand Down Expand Up @@ -227,7 +229,7 @@ var EasyAutocomplete = (function(scope){

var categories = [];

for (var i = 0, length = options.categories.length; i < length; i += 1) {
for (var i = 0, length = options.categories.length; i < length; i += 1) {

var category = options.categories[i];

Expand Down Expand Up @@ -258,27 +260,27 @@ var EasyAutocomplete = (function(scope){
for (var propertyName in source) {
if (target[propertyName] !== undefined && target[propertyName] !== null) {

if (typeof target[propertyName] !== "object" ||
if (typeof target[propertyName] !== "object" ||
target[propertyName] instanceof Array) {
mergedObject[propertyName] = target[propertyName];
} else {
mergeObjects(source[propertyName], target[propertyName]);
}
}
}

/* If data is an object */
if (target.data !== undefined && target.data !== null && typeof target.data === "object") {
mergedObject.data = target.data;
}

return mergedObject;
}
}
}


function processAfterMerge() {

if (defaults.url !== "list-required" && typeof defaults.url !== "function") {
var defaultUrl = defaults.url;
defaults.url = function() {
Expand All @@ -303,7 +305,7 @@ var EasyAutocomplete = (function(scope){
} else {
defaults.listLocation = function(data) {
return data[defaultlistLocation];
};
};
}
}

Expand All @@ -325,9 +327,9 @@ var EasyAutocomplete = (function(scope){
if (options.ajaxSettings !== undefined && typeof options.ajaxSettings === "object") {
defaults.ajaxSettings = options.ajaxSettings;
} else {
defaults.ajaxSettings = {};
defaults.ajaxSettings = {};
}

}

function isAssigned(name) {
Expand All @@ -341,24 +343,23 @@ var EasyAutocomplete = (function(scope){
//Consol is object that should have method log that prints string
//Normally invoke this function with console as consol
function printPropertiesThatDoesntExist(consol, optionsToCheck) {

checkPropertiesIfExist(defaults, optionsToCheck);

function checkPropertiesIfExist(source, target) {
for(var property in target) {
if (source[property] === undefined) {
consol.log("Property '" + property + "' does not exist in EasyAutocomplete options API.");
consol.log("Property '" + property + "' does not exist in EasyAutocomplete options API.");
}

if (typeof source[property] === "object" && $.inArray(property, externalObjects) === -1) {
checkPropertiesIfExist(source[property], target[property]);
}
}
}
}
}
};

return scope;

})(EasyAutocomplete || {});

Loading