src/core/panel.coffee in luca-0.9.1 vs src/core/panel.coffee in luca-0.9.2

- old
+ new

@@ -1,9 +1,9 @@ # This is a helper for creating the DOM element that go along with # a given component, if it is configured to use one via the topToolbar # and bottomToolbar properties -attachToolbar = (config={})-> +attachToolbar = (config={}, targetEl)-> config.orientation ||= "top" config.ctype ||= @toolbarType || "panel_toolbar" id = "#{ @cid }-tbc-#{ config.orientation }" @@ -23,11 +23,11 @@ when "top", "left" if hasBody then "before" else "prepend" when "bottom", "right" if hasBody then "after" else "append" - @$bodyEl()[action]( container ) + (targetEl || @$bodyEl() )[action]( container ) # A Panel is a basic Luca.View but with Toolbar extensions # # In general other components should inherit from the panel class. @@ -40,14 +40,17 @@ # Load Mask will apply a transparent overlay over the form # upon submission, with a moving progress bar which will be # hidden upon successful response loadMask: false loadMaskTemplate: ["components/load_mask"] + loadMaskTimeout: 3000 initialize: (@options={})-> Luca.View::initialize.apply(@, arguments) + _.bindAll @, "applyLoadMask", "disableLoadMask" + if @loadMask is true @defer ()=> @$el.addClass('with-mask') if @$('.load-mask').length is 0 @@ -59,27 +62,39 @@ @on "disable:loadmask", @applyLoadMask loadMaskTarget: ()-> if @loadMaskEl? then @$(@loadMaskEl) else @$bodyEl() + disableLoadMask: ()-> + @$('.load-mask .bar').css("width","100%") + @$('.load-mask').hide() + clearInterval(@loadMaskInterval) + + enableLoadMask: ()-> + @$('.load-mask').show().find('.bar').css("width","0%") + maxWidth = @$('.load-mask .progress').width() + if maxWidth < 20 and (maxWidth = @$el.width()) < 20 + maxWidth = @$el.parent().width() + + @loadMaskInterval = setInterval ()=> + currentWidth = @$('.load-mask .bar').width() + newWidth = currentWidth + 12 + @$('.load-mask .bar').css('width', newWidth) + , 200 + + return unless @loadMaskTimeout? + + _.delay ()=> + @disableLoadMask() + , @loadMaskTimeout + applyLoadMask: ()-> if @$('.load-mask').is(":visible") - @$('.load-mask .bar').css("width","100%") - @$('.load-mask').hide() - clearInterval(@loadMaskInterval) + @disableLoadMask() else - @$('.load-mask').show().find('.bar').css("width","0%") - maxWidth = @$('.load-mask .progress').width() - if maxWidth < 20 and (maxWidth = @$el.width()) < 20 - maxWidth = @$el.parent().width() + @enableLoadMask() - @loadMaskInterval = setInterval ()=> - currentWidth = @$('.load-mask .bar').width() - newWidth = currentWidth + 12 - @$('.load-mask .bar').css('width', newWidth) - , 200 - applyStyles: (styles={},body=false)-> target = if body then @$bodyEl() else @$el for setting, value of styles @@ -112,11 +127,11 @@ $(@el) $wrap: (wrapper)-> - if !wrapper.match(/[<>]/) + if _.isString(wrapper) and not wrapper.match(/[<>]/) wrapper = @make("div",class:wrapper) @$el.wrap( wrapper ) $template: (template, variables={})-> @@ -138,6 +153,6 @@ renderToolbar: (orientation="top", config={})-> config.parent = @ config.orientation = orientation - attachToolbar.call(@, config) + attachToolbar.call(@, config, config.targetEl ) \ No newline at end of file