Navigation Menu

Skip to content

Commit

Permalink
file upload via drag/drop
Browse files Browse the repository at this point in the history
  • Loading branch information
collin committed Dec 16, 2012
1 parent 042c3ce commit e396be0
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/alpha_simprini/client/application.coffee
Expand Up @@ -24,6 +24,7 @@ class AS.Application
bind blur change click dblclick focus focusin focusout bind blur change click dblclick focus focusin focusout
keydown keypress keyup load mousedown mousenter mouseleave mousemove keydown keypress keyup load mousedown mousenter mouseleave mousemove
mouseout mouseover mouseup ready resize scroll select submit load unload mouseout mouseover mouseup ready resize scroll select submit load unload
mousewheel
""" """
def applyTo: (element) -> def applyTo: (element) ->
@el = $(element) @el = $(element)
Expand Down
71 changes: 43 additions & 28 deletions src/alpha_simprini/client/binding/model.coffee
@@ -1,3 +1,4 @@
{isArray} = _
class AS.Binding.Model < AS.Binding class AS.Binding.Model < AS.Binding
def initialize: (@context, @model, @content=$([])) -> def initialize: (@context, @model, @content=$([])) ->
@styles = {} @styles = {}
Expand All @@ -11,25 +12,19 @@ class AS.Binding.Model < AS.Binding
# """ # """


def css: (properties) -> def css: (properties) ->
# for property, options of properties for property, options of properties
# do (property, options) => do (property, options) =>
# if _.isArray(options) if _.isArray(options)
# options = { @styles[property] = => @model.readPath(options)
# path: options painter = => _.defer =>
# fn: => value = @styles[property]()
# value = @styles[property]() @content.css property, value
# @content.css property, value
# }

# @styles[property] = => options.fn(@model)
# painter = => _.defer => @content.css property, @styles[property]()

# {path} = options

# @context.binds @model, options.path, painter, this

_.defer => @paint()


@context.binds @model, options, painter, this
else
@styles[property] = => options.fn(@model)
painter = => _.defer => @content.css property, @styles[property]()
@context.binds @model, options.field, painter, this
# @::css.doc = # @::css.doc =
# params: [ # params: [
# [] # []
Expand All @@ -39,16 +34,36 @@ class AS.Binding.Model < AS.Binding
# """ # """


def attr: (attrs) -> def attr: (attrs) ->
for property, path of attrs for property, options of attrs
do (property, path) => do (property, options) =>
@attrs[property] = => @model.readPath(path) if _.isArray(options)
painter = => @attrs[property] = =>
value = @attrs[property]() value = @model.readPath(options)
@content.attr property, value if value

"yes"
@context.binds @model, path, painter, this else if value in [false, null, undefined]

"no"
_.defer => @paint() else
value
painter = => _.defer =>
@content.attr property, @attrs[property]()
bindingPath = options
@context.binds @model, bindingPath, painter, this
else
@attrs[property] = =>
if options.fn
options.fn(@model)
else
value = @model[options.field].get()
if value
"yes"
else if value in [false, null, undefined]
"no"
else
value
painter = => _.defer =>
@content.attr property, @attrs[property]()
@context.binds @model, options.field, painter, this


# @::attr.doc = # @::attr.doc =
# params: [ # params: [
Expand Down
4 changes: 4 additions & 0 deletions src/alpha_simprini/client/chassis/block.coffee
Expand Up @@ -8,6 +8,10 @@ class AS.Chassis.Block
@appname = "app" @appname = "app"
# window.addEventListener "message", bind(@forwardMessage, this), false # window.addEventListener "message", bind(@forwardMessage, this), false
$ => $ =>
$(window).on "keydown", (event) ->
return if $(event.target).is(":input, [contenteditable]")
event.preventDefault() if event.keyCode is 8

@viewport = $(document.createElement("section")) @viewport = $(document.createElement("section"))
@viewport.addClass("Viewport") @viewport.addClass("Viewport")
@viewport.appendTo(document.body) @viewport.appendTo(document.body)
Expand Down
7 changes: 5 additions & 2 deletions src/alpha_simprini/client/models/targets.coffee
Expand Up @@ -23,7 +23,7 @@ class AS.Models.Targets
# """ # """


def gather: -> def gather: ->
@targets = $(@selector).map (i, el) -> @targets = $(@selector, @application?.el).map (i, el) ->
return el: $(el), rect: el.getBoundingClientRect() return el: $(el), rect: el.getBoundingClientRect()
# @::gather.doc = # @::gather.doc =
# params: [ # params: [
Expand Down Expand Up @@ -64,6 +64,7 @@ class AS.Models.Targets
# """ # """


def drop: (event) -> def drop: (event) ->
@trigger("drop")
# @::drop.doc = # @::drop.doc =
# params: [ # params: [
# [] # []
Expand All @@ -85,7 +86,9 @@ class AS.Models.Targets
# """ # """


def transitionHit: (hit) -> def transitionHit: (hit) ->
return @dropend() if hit is null if hit is null
@currentHit = undefined
return @dropend()
@currentHit ?= AS.Models.Targets.Hit.new() @currentHit ?= AS.Models.Targets.Hit.new()
# Nothin' changed, eh? # Nothin' changed, eh?
return if @currentHit.equals(hit) or hit.rect is undefined return if @currentHit.equals(hit) or hit.rect is undefined
Expand Down
27 changes: 26 additions & 1 deletion src/alpha_simprini/client/view.coffee
Expand Up @@ -343,10 +343,35 @@ class AS.View < AS.DOM
# desc: """ # desc: """
# #
# """ # """

def icon: (name, options={}) -> def icon: (name, options={}) ->
if options.class if options.class
options.class = "#{options.class} icon-#{name}" options.class = "#{options.class} icon-#{name}"
else else
options.class = "icon-#{name}" options.class = "icon-#{name}"
@i options @i options

# @::icon.doc =
# params: [
# ["name", "String", true]
# ["options", Object, false]
# ]
# desc: """
# Creates an <i> element with a class "icon-#{name}", such as
# <i class="icon-magnifier
# """

def preventDefault: (event) -> event.preventDefault()
# @::preventDefault.doc =
# params: [
# [event, "DOMEvent", true]
# ]
# desc: """
# A useful event handler that prevents the default behavior.
# Use it in the events hash like so to prevent navigations on links
# with a 'stopped' class.
# ```coffee
# events:
# "click a.stopped": "preventDefault"
# ```
# """

2 changes: 1 addition & 1 deletion src/alpha_simprini/core/models/file.coffee
Expand Up @@ -32,7 +32,7 @@ class AS.Models.File < AS.Model
defs build: (source) -> defs build: (source) ->
if _.isString(source) if _.isString(source)
@build_from_url(source) @build_from_url(source)
else if source instanceof @::File else if source.lastModifiedDate?
@build_from_filereader(source) @build_from_filereader(source)
# else if source instanceof Image # else if source instanceof Image
# @build_from_image(source) # @build_from_image(source)
Expand Down

0 comments on commit e396be0

Please sign in to comment.