').text(this._data.error).addClass("facet-body-message").appendTo(this._elmts.bodyDiv);
} else {
+ this._elmts.statusDiv.show();
+ this._elmts.controlsDiv.show();
+
var choices = this._data.choices;
var selectionCount = this._selection.length +
(this._blankChoice !== null && this._blankChoice.s ? 1 : 0) +
(this._errorChoice !== null && this._errorChoice.s ? 1 : 0);
-
- /*
- * Status
- */
- var statusDiv = $(
- '
'
- ).appendTo(container);
-
- var statusElmts = DOM.bind(statusDiv);
- if (this._config.expression == "value") {
- statusElmts.clusterLink.click(function() { self._doEdit(); });
- } else {
- statusElmts.clusterLink.hide();
- }
-
- /*
- * Controls
- */
- var controlsDiv = $(
- '
'
- ).appendTo(container);
-
- var controlsElmts = DOM.bind(controlsDiv);
+
+ this._elmts.choiceCountContainer.text(choices.length + " choices");
if (selectionCount > 0) {
- controlsElmts.resetButton.click(function() { self._reset(); });
+ this._elmts.resetButton.show();
} else {
- controlsElmts.resetButton.hide();
+ this._elmts.resetButton.hide();
}
if (this._options.sort == "name") {
- controlsElmts.sortByNameLink.addClass("facet-mode-link-selected");
- controlsElmts.sortByCountLink.click(function() {
- self._options.sort = "count";
- self._reSortChoices();
- self.render();
- });
+ this._elmts.sortByNameLink.addClass("facet-mode-link-selected");
+ this._elmts.sortByCountLink.removeClass("facet-mode-link-selected");
} else {
- controlsElmts.sortByCountLink.addClass("facet-mode-link-selected");
- controlsElmts.sortByNameLink.click(function() {
- self._options.sort = "name";
- self._reSortChoices();
- self.render();
- });
+ this._elmts.sortByNameLink.removeClass("facet-mode-link-selected");
+ this._elmts.sortByCountLink.addClass("facet-mode-link-selected");
}
- /*
- * Body
- */
+ var choiceContainer = $('
');
+
var renderEdit = this._config.expression == "value";
var renderChoice = function(choice, customLabel) {
var label = customLabel || choice.v.l;
var count = choice.c;
- var choiceDiv = $('
').addClass("facet-choice").appendTo(bodyDiv);
+ var choiceDiv = $('
').addClass("facet-choice").appendTo(choiceContainer);
if (choice.s) {
choiceDiv.addClass("facet-choice-selected");
}
@@ -225,16 +233,16 @@ ListFacet.prototype.render = function() {
self._deselect(choice);
};
+ var editLink = $('
')
+ .addClass("facet-choice-link")
+ .text("edit")
+ .css("visibility", "hidden")
+ .prependTo(choiceDiv);
+
if (renderEdit && customLabel === undefined) {
- // edit link
- var editLink = $('
')
- .addClass("facet-choice-link")
- .text("edit")
- .css("visibility", "hidden")
- .click(function() {
- self._editChoice(choice, choiceDiv);
- })
- .prependTo(choiceDiv);
+ editLink.click(function() {
+ self._editChoice(choice, choiceDiv);
+ })
choiceDiv
.mouseenter(function() {
@@ -245,6 +253,13 @@ ListFacet.prototype.render = function() {
});
}
+ var includeExcludeLink = $('
')
+ .addClass("facet-choice-link")
+ .text("include")
+ .css("visibility", "hidden")
+ .click(deselect)
+ .prependTo(choiceDiv);
+
if (choice.s) { // selected
if (selectionCount > 1) {
// select only
@@ -254,30 +269,22 @@ ListFacet.prototype.render = function() {
a.click(deselect);
}
- // exclude link
- $('
')
- .addClass("facet-choice-link")
+ includeExcludeLink
.text("exclude")
- .click(deselect)
- .prependTo(choiceDiv);
+ .css("visibility", "visible")
+ .click(deselect);
} else if (selectionCount > 0) {
a.click(selectOnly);
- // include link
- var includeLink = $('
')
- .addClass("facet-choice-link")
- .text("include")
- .css("visibility", "hidden")
- .click(select)
- .prependTo(choiceDiv);
+ includeExcludeLink.click(select);
choiceDiv
.mouseenter(function() {
- includeLink.css("visibility", "visible");
+ includeExcludeLink.css("visibility", "visible");
})
.mouseleave(function() {
- includeLink.css("visibility", "hidden");
+ includeExcludeLink.css("visibility", "hidden");
});
} else {
a.click(select);
@@ -294,8 +301,8 @@ ListFacet.prototype.render = function() {
renderChoice(this._errorChoice, "(error)");
}
- bodyDiv.appendTo(container);
- bodyDiv[0].scrollTop = scrollTop;
+ this._elmts.bodyDiv.append(choiceContainer);
+ this._elmts.bodyDiv[0].scrollTop = scrollTop;
}
};