class KnobController
elem_tmpl: '<div></div>'
constructor: (@fractalcomponent, @trigger_button) ->
The KnobController is a superclass for things like the:
Notes: There is no reason why KnobController subclasses could not be put in various places along the edges of FractalComponent (rather like the control knobs around the corners of edges of Morphic objects in Squeak).
class KnobController
elem_tmpl: '<div></div>'
constructor: (@fractalcomponent, @trigger_button) ->
@fractalcomponent is the FractalComponent into which the panel which this knob presents should be drawn
@make_panel()
make_panel: (literal_html) ->
literal_html ?= @elem_tmpl
@elem = $(literal_html)
if @css_classes?
@elem.attr('class',@css_classes)
if @main_icon?
@elem.append($("<i class=\"fa fa-#{@main_icon}\"></i> "))
if @elem_label?
@elem.append($("<span>#{@elem_label}</span>"))
@fractalcomponent.elem.append(@elem)
@trigger_button.on "click", () =>
@elem.show()
@elem.on "mouseleave", () =>
@elem.hide()
@elem.hide()
hide_popup: () ->
@elem.hide()
get_visualization_I_accessorize: () ->
return @fractalcomponent.visualization_instance
button_defaults:
icon: 'cog'
make_button_for: (label, action, opt) ->
opt ?= {}
opt.__proto__ = @button_defaults
style = opt.color? and "style=\"color:#{opt.color}\"" or ''
icon = opt.icon? and "<i #{style}class=\"fa fa-#{opt.icon}\"></i> " or ''
button = $("""<button style="display:block">#{icon}#{label}</button>""")
@elem.append(button)
button.on 'click', action
watch_for: (condition, triggers, callback) ->
triggers ?= { attributes: true }
@target = @elem[0]
observer = new MutationObserver (mutations) -> # http://caniuse.com/#feat=mutationobserver
mutations.forEach (mutation) ->
if $(mutation.target).is(condition)
callback()
observer.observe(@target, triggers)
(exports ? this).KnobController = KnobController