|
|
@@ -21,23 +21,40 @@ var RegionSelection;
|
|
|
};
|
|
|
RegionSelectionBox.prototype.showBox = function (e) {
|
|
|
e.preventDefault();
|
|
|
+ e.stopPropagation();
|
|
|
if (this.box === undefined) {
|
|
|
this.renderBox();
|
|
|
}
|
|
|
- this.box.toggle();
|
|
|
+ var box = this.box;
|
|
|
+ var hide = function () {
|
|
|
+ box.hide(0, function () {
|
|
|
+ $('body').off('click', hide);
|
|
|
+ });
|
|
|
+ }.bind(this);
|
|
|
+ if (box.is(':visible')) {
|
|
|
+ hide();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $('body').on('click', hide);
|
|
|
+ box.show(0);
|
|
|
+ }
|
|
|
};
|
|
|
RegionSelectionBox.prototype.renderBox = function () {
|
|
|
- var box = $('<div class="region__selection-box"></div>');
|
|
|
- var itemTemplate = '<a href="{link}" class="region__selection-item">{name}</a>';
|
|
|
- foreach(this.regions, function (region) {
|
|
|
- var item = $(itemTemplate
|
|
|
- .replace('{link}', region.link)
|
|
|
- .replace('{name}', region.caption));
|
|
|
- box.append(item);
|
|
|
- });
|
|
|
- box.css('display', 'none');
|
|
|
- this.selector.parent().append(box);
|
|
|
- this.box = box;
|
|
|
+ var _this = this;
|
|
|
+ if (!$('.region__selection-box').length) {
|
|
|
+ this.box = $('<div class="region__selection-box region-selection__box"></div>');
|
|
|
+ var itemTemplate_1 = '<a href="{link}" class="region-selection__link">{icon} {name}</a>';
|
|
|
+ var iconTemplate_1 = '<img src="{icon}" class="region-selection__icon">';
|
|
|
+ foreach(this.regions, function (region) {
|
|
|
+ var item = $(itemTemplate_1
|
|
|
+ .replace('{link}', region.link)
|
|
|
+ .replace('{name}', region.caption)
|
|
|
+ .replace('{icon}', iconTemplate_1.replace('{icon}', region.icon)));
|
|
|
+ _this.box.append(item);
|
|
|
+ });
|
|
|
+ this.box.css('display', 'none');
|
|
|
+ this.selector.parent().append(this.box);
|
|
|
+ }
|
|
|
};
|
|
|
return RegionSelectionBox;
|
|
|
}());
|