diff --git a/tasks/isp/refactoring/button.js b/tasks/isp/refactoring/button.js index 0f840ed..2a6ab1f 100644 --- a/tasks/isp/refactoring/button.js +++ b/tasks/isp/refactoring/button.js @@ -2,69 +2,82 @@ function notImplemented() { throw new Error('Method is not implemented'); } -function AbstractButton(label) { - this.label = label; - this.$el = this.render(); - this.bind(); -} -AbstractButton.prototype = { - getLabel: function() { - return this.label; - }, - getIcon: function () { +var IView = { + bind: function () { notImplemented(); }, - getUrl: function () { + render: function () { notImplemented(); }, - onClick: function (e) { + getElement: function () { notImplemented(); - }, - render: function () { - var icon = this.getIcon(); - var url = this.getUrl(); - var label = this.getLabel(); - var $el = $(''); - - if (icon) { - $el.append($('').attr('src', icon)); - } + } +}; +var IButton = Object.extend(IView, { + onClick: function () { + notImplemented(); + } +}); - if (label) { - $el.append(label); - } +function AbstractButton() { + this.$el = this.render(); - if (url) { - $el.wrap(''); - } + this.bind(); +} - return $el; - }, +AbstractButton.prototype = Object.extend(IButton, { bind: function () { - this.$el.click(this.onClick); + this.$el.on('click', this.onClick); + }, + getElement: function () { + return this.$el; } -}; +}); function IconButton(icon) { - AbstractButton.call(this, void 0); this.icon = icon; + + AbstractButton.apply(this); } IconButton.prototype = Object.extend(Object.create(AbstractButton.prototype), { getIcon: function () { return this.icon; }, - getUrl: function () {}, - onClick: function (e) {} + render: function () { + var icon = this.getIcon(); + var $el = $(''); + + $el.append($('').attr('src', icon)); + + return $el; + }, + onClick: function (e) { + this.$el.css('opacity', '0.5'); + } }); function AnchorButton(label, url) { - AbstractButton.call(this, label); + this.label = label; this.url = url; + + AbstractButton.apply(this); } AnchorButton.prototype = Object.extend(Object.create(AbstractButton.prototype), { - getIcon: function () {}, getUrl: function () { return this.url; }, - onClick: function (e) {} + getLabel: function () { + return this.label; + }, + render: function () { + var url = this.getUrl(); + var label = this.getLabel(); + + var $el = $('' + label + ''); + + return $el; + }, + onClick: function (e) { + this.$el.css('color', 'red'); + } });