Skip to content
Open
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
66 changes: 35 additions & 31 deletions tasks/isp/refactoring/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,73 @@ function notImplemented() {
throw new Error('Method is not implemented');
}

function AbstractButton(label) {
this.label = label;
function AbstractButton(options) {
this.label = options.label;
this.$el = this.render();
this.bind();
}
AbstractButton.prototype = {
getLabel: function() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У IconButton label никак не используется

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

может использоваться. кнопка, у которой надпись и иконка

return this.label;
},
getIcon: function () {
notImplemented();
},
getUrl: function () {
notImplemented();
},
onClick: function (e) {
notImplemented();
},
onClick: function (e) {},
render: function () {
var icon = this.getIcon();
var url = this.getUrl();
var label = this.getLabel();
var $el = $('<button></button>');

if (icon) {
$el.append($('<img/>').attr('src', icon));
}

if (label) {
$el.append(label);
}

if (url) {
$el.wrap('<a href="' + url + '"></a>');
}

return $el;
},
bind: function () {
this.$el.click(this.onClick);
}
};

function IconButton(icon) {
AbstractButton.call(this, void 0);
this.icon = icon;
function IconButton(options) {
AbstractButton.call(this, options);
this.icon = options.icon;
}
IconButton.prototype = Object.extend(Object.create(AbstractButton.prototype), {
getIcon: function () {
return this.icon;
},
getUrl: function () {},
onClick: function (e) {}
onClick: function (e) {
// some logic
},
render: function () {
var icon = this.getIcon(),
$el = IconButton.prototype.render.call(this);

if (icon) {
$el.append($('<img/>').attr('src', icon));
}

return $el;
}
});

function AnchorButton(label, url) {
AbstractButton.call(this, label);
this.url = url;
function AnchorButton(options) {
AbstractButton.call(this, options);
this.url = options.url || '#';
}
AnchorButton.prototype = Object.extend(Object.create(AbstractButton.prototype), {
getIcon: function () {},
getUrl: function () {
return this.url;
},
onClick: function (e) {}
onClick: function (e) {
// some logic
},
render: function () {
var label = this.getLabel();
var $el = $('<a href="' + this.getUrl() + '"></a>');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offtop: ссылка должна оборачивать кнопку

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не юзабельно ведь. сделали как в бутстрапе, типа ссылка стилизуется под кнопку. и кнопка блочный элемент, а ссылка инлайн

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Собственно в лего точно так же делается


if (label) {
$el.append(label);
}

return $el;
}
});