X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=app%2Fassets%2Fjavascripts%2Ftags.js.coffee;h=a50bcd4751775dc337b404b5d1f7f219c10b6c6c;hp=c95a2916cd232cf0a04fa0c7a2b4fc9ed78713c7;hb=9edc3731389bcae0de05ef6045cceb6b7581cc8f;hpb=eec19634998fd448e4bb1be831260537199d8271 diff --git a/app/assets/javascripts/tags.js.coffee b/app/assets/javascripts/tags.js.coffee index c95a2916..a50bcd47 100644 --- a/app/assets/javascripts/tags.js.coffee +++ b/app/assets/javascripts/tags.js.coffee @@ -1,6 +1,6 @@ class Tag -class Tag.Img extends Backbone.View +class Tag.Img extends Pettanr.View tagName: 'img' # attr: {src: '/hoge', width: 80, ...} @@ -14,12 +14,11 @@ class Tag.Img extends Backbone.View this.$el.addClass(@class_name) if @class_name this -class Tag.A extends Backbone.View +class Tag.A_ extends Pettanr.View tagName: 'a' initialize: (options) -> @attr = options.attr || {} - @handler_name = options.handler_name @content = options.content @class_name = options.class_name @@ -27,16 +26,24 @@ class Tag.A extends Backbone.View this.$el.attr(@attr) @el.className = @class_name if @class_name this.$el.html(@content) - if @handler_name - @events = {click: 'click'} - @delegateEvents(@events) + this + +class Tag.A extends Tag.A_ + + initialize: (options) -> + super(options) + + render: () -> + super() + @events = {click: 'click'} + @delegateEvents(@events) this click: () -> - window.router.navigate(@handler_name, true) + @trigger('click') return false -class Tag.Div extends Backbone.View +class Tag.Div extends Pettanr.View tagName: 'div' initialize: (options) -> @@ -49,14 +56,33 @@ class Tag.Div extends Backbone.View this.$el.attr(@attr) this.$el.html(@content) this + +class Tag.Span extends Tag.Div + tagName: 'span' +class Tag.Ul extends Pettanr.View + tagName: 'ul' + + initialize: (options) -> + @attr = options.attr || {} + @contents = options.contents + @class_name = options.class_name + + render: () -> + @el.className = @class_name if @class_name + this.$el.attr(@attr) + this.$el.html('') + _.each @contents, (content) => + this.$el.append(content.render().el) + this + class Tag.RowBreak extends Tag.Div initialize: (options) -> @attr = {} @content = null @class_name = 'row_break' -class Tag.H3 extends Backbone.View +class Tag.H3 extends Pettanr.View tagName: 'h3' initialize: (options) -> @@ -70,4 +96,85 @@ class Tag.H3 extends Backbone.View this.$el.html(@content) this +class Tag.H2 extends Tag.H3 + tagName: 'h2' + +class Tag.Input extends Pettanr.View + tagName: 'input' + + initialize: (options) -> + @type = options.type || 'text' + @class_name = options.class_name + @attr = {} + + render: () -> + this.$el.attr(@attr) + @el.className = @class_name if @class_name + this.$el.html('') + this + +class Tag.Checkbox extends Tag.Input + events: { + click: 'click' + } + + initialize: (options) -> + super(options) + @type = 'checkbox' + @value = options.value + @checked = options.checked + @attr = { + type: @type, + value: @value, + checked: @checked, + } + + refresh: () -> + @attr['checked'] = @checked + this.$el.attr(@attr) + + click: () -> + @checked = this.$el.prop('checked') + @refresh() + @trigger('click') + return true + +class Tag.Submit extends Tag.Input + events: { + click: 'click' + } + + initialize: (options) -> + super(options) + @type = 'submit' + @value = options.value + @attr = { + type: @type, + value: @value, + } + + click: () -> + @trigger('click') + return false + +class Tag.Option extends Pettanr.View + tagName: 'option' + + initialize: (options) -> + super(options) + @selected = options.selected + @value = options.value || '' + @caption = options.caption + + render: () -> + this.$el.attr({value: @value, selected: @sel_attr()}) + this.$el.html(@caption) + this + + sel_attr: () -> + if @selected + 'selected' + else + '' + @Tag = Tag