Skip to content

Commit

Permalink
Refactored search
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Kohlhepp committed May 28, 2011
1 parent 9d9d4c1 commit daceb06
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion source/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ body.searching #search-result-container {
}

body.measuring .tab-content, body.measuring #search-result-container {
display: block;
display: block !important;
opacity: 0;
overflow: hidden;
}
3 changes: 2 additions & 1 deletion source/js/classes/fancy-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@

settings.each(function (setting) {
if (setting.params.type !== type) {
console.error("Only one type per group is allowed.");
throw "multipleTypes";
}

Expand All @@ -111,8 +110,10 @@
if (width < maxWidth) {
if (type === "button" || type === "slider") {
setting.element.setStyle("margin-left", (maxWidth - width + 2) + "px");
setting.search.element.setStyle("margin-left", (maxWidth - width + 2) + "px");
} else {
setting.element.setStyle("margin-left", (maxWidth - width) + "px");
setting.search.element.setStyle("margin-left", (maxWidth - width) + "px");
}
}
});
Expand Down
48 changes: 26 additions & 22 deletions source/js/classes/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

this.search = search;
this.searchResultContainer = searchResultContainer;
this.setting = new Setting(new Element("div"));

// Create setting for message "nothing found"
setting = new Setting(this.searchResultContainer);
Expand Down Expand Up @@ -43,40 +44,44 @@
},

"add": function (setting) {
this.index.push(setting);
},

"find": function (searchString) {
var result,
groupName,
group,
row,
content
var searchSetting = this.setting.create(setting.params);
setting.search = searchSetting;
searchSetting.original = setting;
this.index.push(searchSetting);

// Reset all settings
this.index.each(function (setting) {
setting.bundle.inject(setting.bundleContainer);
setting.addEvent("action", function (value, stopPropagation) {
if (searchSetting.set !== undefined && stopPropagation !== true) {
searchSetting.set(value, true);
}
});

// Hide all groups
Object.each(this.groups, function (group) {
group.dispose();
searchSetting.addEvent("action", function (value) {
if (setting.set !== undefined) {
setting.set(value, true);
}
setting.fireEvent("action", [value, true]);
});

},

"find": function (searchString) {
// Exit search mode
if (searchString.trim() === "") {
document.body.removeClass("searching");
return;
}

// Or enter search mode
this.index.each(function (setting) { setting.bundle.dispose(); });
Object.each(this.groups, function (group) { group.dispose(); });
document.body.addClass("searching");
result = this.index.filter(function (setting) {

// Filter settings
var result = this.index.filter(function (setting) {
if (setting.params.searchString.contains(searchString.trim().toLowerCase())) {
return true;
}
});

// Display settings
result.each((function (setting) {
var group,
row;
Expand All @@ -86,9 +91,9 @@
this.groups[setting.params.group] = (new Element("table", {
"class": "setting group"
})).inject(this.searchResultContainer);
group = this.groups[setting.params.group];

var row = (new Element("tr")).inject(group);
group = this.groups[setting.params.group];
row = (new Element("tr")).inject(group);

(new Element("td", {
"class": "setting group-name",
Expand All @@ -99,8 +104,7 @@
"class": "setting group-content"
})).inject(row);
} else {
group = this.groups[setting.params.group];
group.inject(this.searchResultContainer);
group = this.groups[setting.params.group].inject(this.searchResultContainer);
}

setting.bundle.inject(group.content);
Expand Down
8 changes: 6 additions & 2 deletions source/js/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
//
(function () {
var lang = navigator.language.split("-")[0];
if (typeOf(this.i18n) !== "object") { this.i18n = {}; }
if (this.i18n === undefined) { this.i18n = {}; }
this.i18n.get = function (value) {
if (value === "lang") {
return lang;
}

if (this.hasOwnProperty(value)) {
value = this[value];
if (value.hasOwnProperty(lang)) {
Expand All @@ -17,7 +21,7 @@
return Object.values(value)[0];
}
} else {
return undefined;
return value;
}
};
}());

0 comments on commit daceb06

Please sign in to comment.