Skip to content

Commit

Permalink
refactoring, styling
Browse files Browse the repository at this point in the history
  • Loading branch information
maccman committed Apr 16, 2012
1 parent 20534f2 commit 19693b7
Show file tree
Hide file tree
Showing 17 changed files with 250 additions and 161 deletions.
10 changes: 6 additions & 4 deletions assets/javascripts/app/controllers/inspector.module.coffee
Expand Up @@ -75,10 +75,7 @@ class Inspector extends Spine.Controller
# Make sure only one inspector is active # Make sure only one inspector is active
@manager = new Spine.Manager @manager = new Spine.Manager
@manager.add(@textInspector, @displayInspector) @manager.add(@textInspector, @displayInspector)
@manager.bind 'change', (controller) => @manager.bind 'change', @changeHeader
name = controller.constructor.name
@$headers.removeClass('active')
@$headers.filter("[data-type=#{name}]").addClass('active')


# Display the display inspector by default # Display the display inspector by default
@displayInspector.active() @displayInspector.active()
Expand Down Expand Up @@ -117,6 +114,11 @@ class Inspector extends Spine.Controller
@textInspector.render() @textInspector.render()
@textInspector.active() @textInspector.active()


changeHeader: =>
name = @manager.current.constructor.name
@$headers.removeClass('active')
@$headers.filter("[data-type=#{name}]").addClass('active')

release: -> release: ->
@textInspector.release() @textInspector.release()
@displayInspector.release() @displayInspector.release()
Expand Down
Expand Up @@ -16,9 +16,8 @@ class BorderController extends Spine.Controller


current: 'border' current: 'border'


render: => constructor: ->
@disabled = not @stage.selection.isAny() super
@disabled = true if @stage.selection.get('border') is false


@html JST['app/views/inspector/border'](this) @html JST['app/views/inspector/border'](this)


Expand All @@ -27,12 +26,19 @@ class BorderController extends Spine.Controller
@$color.bind 'change', => @inputChange() @$color.bind 'change', => @inputChange()


@$('input[type=color]').replaceWith(@$color.el) @$('input[type=color]').replaceWith(@$color.el)

render: =>
@disabled = not @stage.selection.isAny()
@disabled = true if @stage.selection.get('border') is false

@change(@current) @change(@current)


@el.toggleClass('disabled', @disabled) @el.toggleClass('disabled', @disabled)
@$inputs.attr('disabled', @disabled) @$inputs.attr('disabled', @disabled)
this this


# Private

change: (@current) -> change: (@current) ->
return if @disabled return if @disabled


Expand Down
Expand Up @@ -11,20 +11,25 @@ class BorderRadius extends Spine.Controller


current: 'borderRadius' current: 'borderRadius'


constructor: ->
super
@html JST['app/views/inspector/border_radius'](this)

render: => render: =>
# Disable unless elements are selected or if an # Disable unless elements are selected or if an
# element, such as an ellipsis, is selected. # element, such as an ellipsis, is selected.
@disabled = not @stage.selection.isAny() @disabled = not @stage.selection.isAny()
@disabled = true if @stage.selection.get('borderRadius') is false @disabled = true if @stage.selection.get('borderRadius') is false


@html JST['app/views/inspector/border_radius'](this)
@change(@current) @change(@current)


@el.toggleClass('disabled', @disabled) @el.toggleClass('disabled', @disabled)
@$inputs.attr('disabled', @disabled) @$inputs.attr('disabled', @disabled)


this this


# Private

change: (@current) -> change: (@current) ->
return if @disabled return if @disabled


Expand Down
Expand Up @@ -24,54 +24,51 @@ class BoxShadowEdit extends Spine.Controller
@render() @render()


render: -> render: ->
@html JST['app/views/inspector/box_shadow'](@) @$color = new ColorPicker.Preview(

@colorInput = new ColorPicker.Preview(
color: @shadow.color color: @shadow.color
el: @$('.colorInput')
) )


@colorInput.bind 'change', (color) => @$color.bind 'change', (color) => @inputChange()
@shadow.color.set color
@trigger 'change', @shadow
@update()


@positionPicker = new PositionPicker( @$position = new PositionPicker
el: @$('.positionInput')
)


@positionPicker.bind 'change', (position) => @$position.bind 'change', (position) =>
@shadow.x = position.left @shadow.x = position.left
@shadow.y = position.top @shadow.y = position.top
@trigger 'change', @shadow @trigger 'change', @shadow
@update() @update()


@html JST['app/views/inspector/box_shadow'](@)
@$('input[type=color]').replaceWith(@$color.el)
@$('input[type=position]').replaceWith(@$position.el)

@update() @update()
this this


update: -> update: ->
@$inputs.attr('disabled', @disabled) @$inputs.attr('disabled', @disabled)
@positionPicker.disabled = @disabled


@positionPicker.change( @$position.change(
left: @shadow.x, top: @shadow.y left: @shadow.x, top: @shadow.y
) )


@$x.val @shadow.x @$x.val @shadow.x
@$y.val @shadow.y @$y.val @shadow.y
@$blur.val @shadow.blur @$blur.val @shadow.blur
@$color.val @shadow.color


inputChange: (e) -> inputChange: (e) ->
@shadow.x = parseFloat(@$x.val()) @shadow.x = parseFloat(@$x.val())
@shadow.y = parseFloat(@$y.val()) @shadow.y = parseFloat(@$y.val())
@shadow.blur = parseFloat(@$blur.val()) or 0 @shadow.blur = parseFloat(@$blur.val()) or 0
@shadow.color = @$color.val()


@trigger 'change', @shadow @trigger 'change', @shadow
@update() @update()


release: -> release: ->
@colorInput?.release() @$color?.release()
@positionPicker?.release() @$position?.release()
super super


class BoxShadowList extends Spine.Controller class BoxShadowList extends Spine.Controller
Expand Down
Expand Up @@ -14,11 +14,11 @@ class Dimensions extends Spine.Controller
constructor: -> constructor: ->
super super
$(document).bind 'resize.element move.element', @update $(document).bind 'resize.element move.element', @update
@html JST['app/views/inspector/dimensions'](this)


render: => render: =>
@disabled = not @stage.selection.isSingle() @disabled = not @stage.selection.isSingle()


@html JST['app/views/inspector/dimensions'](this)
@update() @update()


@el.toggleClass('disabled', @disabled) @el.toggleClass('disabled', @disabled)
Expand Down
Expand Up @@ -16,27 +16,27 @@ class TextShadow extends Spine.Controller
constructor: -> constructor: ->
super super


@positionPicker = new PositionPicker @$position = new PositionPicker


@positionPicker.bind 'change', (position) => @$position.bind 'change', (position) =>
@shadow.x = position.left @shadow.x = position.left
@shadow.y = position.top @shadow.y = position.top
@stage.selection.set('textShadow', @shadow) @set()
@update() @update()


@$color = new ColorPicker.Preview @$color = new ColorPicker.Preview
@$color.bind 'change', => @change() @$color.bind 'change', => @change()


@html JST['app/views/inspector/text_shadow'](@)
@$('input[type=color]').replaceWith(@$color.el)
@$('input[type=position]').replaceWith(@$position.el)

render: -> render: ->
@disabled = not @stage.selection.isAny() @disabled = not @stage.selection.isAny()


@shadow = @stage.selection.get('textShadow') @shadow = @stage.selection.get('textShadow')
@shadow or= new Shadow @shadow or= new Shadow


@html JST['app/views/inspector/text_shadow'](@)
@$('input[type=color]').replaceWith(@$color.el)
@append @positionPicker

@update() @update()


this this
Expand All @@ -55,17 +55,25 @@ class TextShadow extends Spine.Controller
@shadow.blur = parseFloat(@$blur.val()) @shadow.blur = parseFloat(@$blur.val())
@shadow.color = @$color.val() @shadow.color = @$color.val()


@positionPicker.change( @$position.change(
left: @shadow.x, left: @shadow.x,
top: @shadow.y top: @shadow.y
) )


@set()
@update()

set: ->
# Text shadows need a blur
# to be formatted correctly
@shadow.blur ?= 0

@stage.history.record('textShadow') @stage.history.record('textShadow')
@stage.selection.set('textShadow', @shadow) @stage.selection.set('textShadow', @shadow)
@update()


release: -> release: ->
@positionPicker?.release() @$position?.release()
@$color?.release()
super super


module.exports = TextShadow module.exports = TextShadow
4 changes: 2 additions & 2 deletions assets/javascripts/app/views/inspector/box_shadow.jst.eco
@@ -1,6 +1,6 @@
<article> <article>
<div class="hbox"> <div class="hbox">
<div class="positionInput"></div> <input type="position" name="position">


<div class="vbox"> <div class="vbox">
<label> <label>
Expand All @@ -22,7 +22,7 @@


<label class="color"> <label class="color">
<span>Color</span> <span>Color</span>
<div class="colorInput"></div> <input type="color" name="color">
</label> </label>
</div> </div>
</div> </div>
Expand Down
37 changes: 24 additions & 13 deletions assets/javascripts/app/views/inspector/text_shadow.jst.eco
@@ -1,20 +1,31 @@
<h3>Text Shadow</h3> <h3>Text Shadow</h3>


<article> <article>
<label> <div class="hbox">
<span>X</span> <input type="position" name="position">
<input type="number" name="x" placeholder="0px">
</label>


<label> <div class="vbox">
<span>Y</span> <label>
<input type="number" name="y" placeholder="0px"> <span>X</span>
</label> <input type="number" name="x" placeholder="0px">
</label>


<label> <label>
<span>Blur</span> <span>Y</span>
<input type="number" name="blur" placeholder="0px"> <input type="number" name="y" placeholder="0px">
</label> </label>
</div>


<input type="color" name="color"> <div class="vbox">
<label class="blur">
<span>Blur</span>
<input type="number" name="blur" placeholder="0px">
</label>

<label class="color">
<span>Color</span>
<input type="color" name="color">
</label>
</div>
</div>
</article> </article>
21 changes: 21 additions & 0 deletions assets/stylesheets/app/inspector/text_shadow.css.styl
@@ -0,0 +1,21 @@
#app .inspector .textShadow {
.positionPicker {
margin: 3px 5px 3px 0
}

label {
span {
margin-left: 3px
width: auto
}
}

.blur span, .color span {
width: 33px
}

.color span {
position relative
top: -6px
}
}
18 changes: 10 additions & 8 deletions public/assets/app/controllers/inspector.module.js
Expand Up @@ -197,11 +197,11 @@ this.require.define({"app/controllers/inspector":function(exports, require, modu
}; };


function Inspector() { function Inspector() {
this.changeHeader = __bind(this.changeHeader, this);

this.render = __bind(this.render, this); this.render = __bind(this.render, this);


this.paint = __bind(this.paint, this); this.paint = __bind(this.paint, this);

var _this = this;
Inspector.__super__.constructor.apply(this, arguments); Inspector.__super__.constructor.apply(this, arguments);
this.append(JST['app/views/inspector']()); this.append(JST['app/views/inspector']());
this.append(this.textInspector = new TextInspector({ this.append(this.textInspector = new TextInspector({
Expand All @@ -212,12 +212,7 @@ this.require.define({"app/controllers/inspector":function(exports, require, modu
})); }));
this.manager = new Spine.Manager; this.manager = new Spine.Manager;
this.manager.add(this.textInspector, this.displayInspector); this.manager.add(this.textInspector, this.displayInspector);
this.manager.bind('change', function(controller) { this.manager.bind('change', this.changeHeader);
var name;
name = controller.constructor.name;
_this.$headers.removeClass('active');
return _this.$headers.filter("[data-type=" + name + "]").addClass('active');
});
this.displayInspector.active(); this.displayInspector.active();
this.stage.selection.bind('change', this.paint); this.stage.selection.bind('change', this.paint);
this.render(); this.render();
Expand Down Expand Up @@ -254,6 +249,13 @@ this.require.define({"app/controllers/inspector":function(exports, require, modu
} }
}; };


Inspector.prototype.changeHeader = function() {
var name;
name = this.manager.current.constructor.name;
this.$headers.removeClass('active');
return this.$headers.filter("[data-type=" + name + "]").addClass('active');
};

Inspector.prototype.release = function() { Inspector.prototype.release = function() {
this.textInspector.release(); this.textInspector.release();
this.displayInspector.release(); this.displayInspector.release();
Expand Down

0 comments on commit 19693b7

Please sign in to comment.