Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added documentation stubs

  • Loading branch information...
commit 271d37adf1cd655e48b8eb0e9619a4711e282a73 1 parent f7ce1ec
@collin authored
Showing with 1,134 additions and 117 deletions.
  1. +1 −14 Assetfile
  2. +3 −3 Rakefile
  3. +1 −1  src/alpha_simprini.coffee
  4. +37 −3 src/alpha_simprini/client/application.coffee
  5. +42 −0 src/alpha_simprini/client/binding.coffee
  6. +28 −0 src/alpha_simprini/client/binding/check_box.coffee
  7. +21 −0 src/alpha_simprini/client/binding/container.coffee
  8. +74 −4 src/alpha_simprini/client/binding/edit_line.coffee
  9. +29 −1 src/alpha_simprini/client/binding/field.coffee
  10. +28 −0 src/alpha_simprini/client/binding/file.coffee
  11. +42 −0 src/alpha_simprini/client/binding/input.coffee
  12. +70 −1 src/alpha_simprini/client/binding/many.coffee
  13. +28 −2 src/alpha_simprini/client/binding/model.coffee
  14. +14 −0 src/alpha_simprini/client/binding/one.coffee
  15. +21 −9 src/alpha_simprini/client/binding/select.coffee
  16. +48 −1 src/alpha_simprini/client/binding_group.coffee
  17. +49 −0 src/alpha_simprini/client/dom.coffee
  18. +145 −23 src/alpha_simprini/client/models/targets.coffee
  19. +166 −21 src/alpha_simprini/client/view.coffee
  20. +56 −0 src/alpha_simprini/client/view_events.coffee
  21. +49 −0 src/alpha_simprini/client/view_model.coffee
  22. +0 −1  src/alpha_simprini/client/views/canvas.coffee
  23. +99 −12 src/alpha_simprini/client/views/dialog.coffee
  24. +36 −0 src/alpha_simprini/client/views/region.coffee
  25. +8 −1 src/alpha_simprini/client/views/stage.coffee
  26. +7 −0 src/alpha_simprini/core/callbacks.coffee
  27. +5 −2 src/alpha_simprini/core/model.coffee
  28. +2 −1  src/alpha_simprini/core/model/rest.coffee
  29. +1 −1  src/alpha_simprini/core/models/file.coffee
  30. +9 −1 test/client/binding/check_box.coffee
  31. +15 −15 test/client/models/targets.coffee
View
15 Assetfile
@@ -4,7 +4,7 @@ require "json"
output "dist"
input "lib" do
- match "/**/*.js" do
+ match "**/*.js" do
minispade rewrite_requires: true, string: true, module_id_generator: proc { |input|
id = input.path.dup
id.sub!('/lib/', '/')
@@ -17,22 +17,9 @@ input "lib" do
end
end
-# TODO: include a raw distribution
-# input "lib", "**/*.js" do
-# neuter { "alpha_simprini.js" }
-# end
-
input "./", "alpha_simprini.erb" do
require "./version"
filter(Rake::Pipeline::Web::Filters::TiltFilter, {}, Object) do |input|
"alpha_simprini.html"
end
end
-
-
-# output "dist/test"
-# input "tmp/test" do
-# match "**/*.js" do
-# neuter
-# end
-# end
View
6 Rakefile
@@ -55,11 +55,11 @@ task :upload => :test do
uploader = GithubUploader.setup_uploader
# TODO: release a raw distribution
# GithubUploader.upload_file uploader, "Alpha Simprini-#{AS_VERSION}.js", "Alpha Simprini #{AS_VERSION}", "dist/alpha_simprini.js"
- GithubUploader.upload_file uploader, "Alpha Simprini-#{AS_VERSION}-spade.js", "Alpha Simprini #{AS_VERSION} (minispade)", "dist/alpha_simprini-spade.js"
- GithubUploader.upload_file uploader, "Alpha Simprini-#{AS_VERSION}.html", "Alpha Simprini #{AS_VERSION} (html_package)", "dist/alpha_simprini.html"
+ GithubUploader.upload_file uploader, "alpha_simprini-#{AS_VERSION}-spade.js", "Alpha Simprini #{AS_VERSION} (minispade)", "dist/alpha_simprini-spade.js"
+ GithubUploader.upload_file uploader, "alpha_simprini-#{AS_VERSION}.html", "Alpha Simprini #{AS_VERSION} (html_package)", "dist/alpha_simprini.html"
# GithubUploader.upload_file uploader, 'Alpha Simprini-latest.js', "Current Alpha Simprini", "dist/alpha_simprini.js"
- GithubUploader.upload_file uploader, 'Alpha Simprini-latest-spade.js', "Current Alpha Simprini (minispade)", "dist/alpha_simprini-spade.js"
+ GithubUploader.upload_file uploader, 'alpha_simprini-latest-spade.js', "Current Alpha Simprini (minispade)", "dist/alpha_simprini-spade.js"
end
desc "Create json document object"
View
2  src/alpha_simprini.coffee
@@ -28,7 +28,7 @@ AS.Property = Taxi.Property
AS.COLLECTION_DELEGATES = ["first", "rest", "last", "compact", "flatten", "without", "union", "filter", "reverse",
"intersection", "difference", "uniq", "zip", "indexOf", "find", "detect", "sortBy",
- "lastIndexOf", "range", "include", "each", "map", "reject","all", "toArray", "pluck"]
+ "lastIndexOf", "range", "include", "each", "map", "reject","all", "toArray", "pluck", "invoke"]
AS.require = (framework="alpha_simprini", libraries) ->
if libraries is undefined
View
40 src/alpha_simprini/client/application.coffee
@@ -9,14 +9,28 @@ AS.Application = AS.Object.extend ({def, include}) ->
_.extend(this, config)
@params = AS.params
@el ?= $("body")
- @god_given_key_handlers()
+ @godGivenKeyHandlers()
domready =>
@boot()
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def boot: ->
+ # @::boot.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
- def god_given_key_handlers: ->
+ def godGivenKeyHandlers: ->
handlers =
'': 'escape'
'⌘+↩': 'accept'
@@ -39,13 +53,33 @@ AS.Application = AS.Object.extend ({def, include}) ->
jwerty.key key, ( (event) => @trigger(trigger, event) ), @el
jwerty.key "backspace", (event) =>
- event.preventDefault()
@trigger("delete", event)
+ # @::godGivenKeyHandlers.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def view: (constructor, options={}) ->
options.application = this
constructor.new options
+ # @::view.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def append: (view) ->
@el.append view.el
+ # @::append.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
42 src/alpha_simprini/client/binding.coffee
@@ -16,23 +16,65 @@ AS.Binding = AS.Object.extend ({def}) ->
@bindingGroup = bindingGroup
@setup()
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def makeContent: ->
@context.$ []
+ # @::makeContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def willGroupBindings: ->
@constructor.willGroupBindings or _.isFunction(@fn)
+ # @::willGroupBindings.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def fieldValue: ->
if _.isArray(@field)
@model.readPath(@field)
else
@field.get()
+ # @::fieldValue.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def require_option: (name) ->
return unless @options[name] is undefined
throw new AS.Binding.MissingOption("You must specify the #{name} option for #{@constructor.name} bindings.")
+ # @::requireOption.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def setup: ->
+ # @::setup.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
class AS.Binding.MissingOption extends Error
View
28 src/alpha_simprini/client/binding/check_box.coffee
@@ -2,15 +2,43 @@ AS.Binding.CheckBox = AS.Binding.Input.extend ({def}) ->
def initialize: (context, model, field, options={}, fn=undefined) ->
options.type = "checkbox"
@_super.apply(this, arguments)
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def setContent: ->
@content.attr "checked", @fieldValue()
+ # @::setContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def bindContent: ->
@context.binds @content, "change", _.bind(@setField, this)
+ # @::bindContext.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def setField: ->
if @content.is ":checked"
@field.set true
else
@field.set false
+ # @::setField.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
21 src/alpha_simprini/client/binding/container.coffee
@@ -4,6 +4,13 @@ AS.Binding.Container = AS.Object.extend ({delegate, include, def, defs}) ->
def initialize: (@domElement) ->
@el = jQuery(@domElement)
@containerChildren = []
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def appendChild: (child) ->
if child instanceof jQuery
@@ -12,7 +19,21 @@ AS.Binding.Container = AS.Object.extend ({delegate, include, def, defs}) ->
else
@containerChildren.push child
@domElement.appendChild(child)
+ # @::appendChild.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def empty: ->
jQuery(@containerChildren).remove()
@containerChildren = []
+ # @::empty.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
78 src/alpha_simprini/client/binding/edit_line.coffee
@@ -13,18 +13,39 @@ AS.Binding.EditLine = AS.Binding.extend ({def}) ->
doc.del commonStart, oldval.length - commonStart - commonEnd unless oldval.length == commonStart + commonEnd
doc.insert commonStart, newval[commonStart ... newval.length - commonEnd] unless newval.length == commonStart + commonEnd
+ # @::applyChange.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def transformInsertCursor = (text, position, cursor) ->
if position < cursor
cursor + text.length
else
cursor
+ # @::transformInsertCursor.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def transformDeleteCursor = (text, position, cursor) ->
if position < cursor
cursor - Math.min(text.length, cursor - position)
else
cursor
+ # @::transformDeleteCursor.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def initialize: ->
@_super.apply(this, arguments)
@@ -42,17 +63,38 @@ AS.Binding.EditLine = AS.Binding.extend ({def}) ->
for event in ['textInput', 'keydown', 'keyup', 'select', 'cut', 'paste', 'click', 'focus']
@context.binds @content, event, @generateOperation, this
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def updateUnlessFocused: (event) ->
# Defer this because we want text input to feel fluid!
_.defer ->
return if @context.$(this.elem).closest(":focus")[0]
@elem.innerHTML = @fieldValue()
+ # @::updateUnlessFocused.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def makeContent: ->
@context.$ @context.span(@options)
-
- def replace_text: (new_text="") ->
+ # @::makeContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
+
+ def replaceText: (new_text="") ->
range = @rangy.createRange()
selection = @rangy.getSelection()
@@ -64,18 +106,39 @@ AS.Binding.EditLine = AS.Binding.extend ({def}) ->
range.setStart(selection.anchorNode || @elem.childNodes[0] || @elem, @selection.start)
range.collapse(true)
selection.setSingleRange(range)
+ # @::replaceText.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def insert: (model, position, text) ->
@selection.start = transformInsertCursor(text, position, @selection.start)
@selection.end = transformInsertCursor(text, position, @selection.end)
- @replace_text @elem.innerHTML[...position] + text + @elem.innerHTML[position..]
+ @replaceText @elem.innerHTML[...position] + text + @elem.innerHTML[position..]
+ # @::insert.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def delete: (model, position, text) ->
@selection.start = transformDeleteCursor(text, position, @selection.start)
@selection.end = transformDeleteCursor(text, position, @selection.end)
- @replace_text @elem.innerHTML[...position] + @elem.innerHTML[position + text.length..]
+ @replaceText @elem.innerHTML[...position] + @elem.innerHTML[position + text.length..]
+ # @::delete.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def generateOperation: ->
selection = @rangy.getSelection()
@@ -91,3 +154,10 @@ AS.Binding.EditLine = AS.Binding.extend ({def}) ->
# should only have unix newlines.
@applyChange @model.share.at(@field), @model.share.at(@field).getText(), @elem.innerHTML.replace(/\r\n/g, '\n')
@model[@field] @model.share.at(@field).getText(), remote: true
+ # @::generateOperation.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
30 src/alpha_simprini/client/binding/field.coffee
@@ -3,11 +3,25 @@ AS.Binding.Field = AS.Binding.extend ({def}) ->
@_super.apply this, arguments
@setContent()
@bindContent()
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def bindContent: ->
# don't go thinking ou want to @withingBindingGroup @bindingGroup this.
# you want this binding to take place in the context of the @context
@context.binds @field, "change", @setContent, this
+ # @::bindContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def setContent: ->
if @fn
@@ -34,9 +48,23 @@ AS.Binding.Field = AS.Binding.extend ({def}) ->
@fn.call(@context)
else
@content.text @fieldValue()
+ # @::setContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def makeContent: ->
if @fn
AS.Binding.Container.new(@container[0])
else
- @context.$ @context.span()
+ @context.$ @context.span()
+ # @::makeContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
28 src/alpha_simprini/client/binding/file.coffee
@@ -3,10 +3,38 @@ AS.Binding.File = AS.Binding.Input.extend ({delegate, include, def, defs}) ->
options = _.clone(@options)
options.type = "file"
@context.$ @context.input(options)
+ # @::makeContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def fieldValue: -> # FALSE. Cannot set value of a file input.
+ # @::fieldValue.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def setContent: -> # FALSE. Cannot set value of a file input.
+ # @::setContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def readField: ->
AS.Models.File.new file: @content[0].files[0]
+ # @::readField.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
42 src/alpha_simprini/client/binding/input.coffee
@@ -5,21 +5,63 @@ AS.Binding.Input = AS.Binding.Field.extend ({def}) ->
@context.binds @model, @field, @setContent, this
else
@context.binds @field, "change", @setContent, this
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def makeContent: ->
@context.$ @context.input(@options)
+ # @::makeContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def bindContent: ->
@context.binds @content, "change", @setField, this
+ # @::bindContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def setContent: () ->
@content.val @fieldValue()
+ # @::setContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def readField: ->
@content.val()
+ # @::readFile.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def setField: () ->
if _.isArray @field
@model.writePath @field, @readField()
else
@field.set @readField()
+ # @::setField.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
71 src/alpha_simprini/client/binding/many.coffee
@@ -13,15 +13,36 @@ AS.Binding.Many = AS.Binding.extend ({def}) ->
@context.binds @collection, "add", @insertItem, this
@context.binds @collection, "remove", @removeItem, this
@context.binds @collection, "change", @changeItem, this
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def makeAll: ->
@sortedModels().each _.bind @makeItemContent, this
+ # @::makeAll.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def sortedModels: ->
if sortField = @options.order_by
@collection.sortBy((item) -> item[sortField].get())
else
@collection
+ # @::sortedModels.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def skipItem: (item) ->
return false unless @options.filter
@@ -32,6 +53,13 @@ AS.Binding.Many = AS.Binding.extend ({def}) ->
return true unless _(expectedValue).include(valueOnItem)
false
+ # @::skipItem.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def insertItem: (item) ->
return if @skipItem(item)
@@ -50,8 +78,14 @@ AS.Binding.Many = AS.Binding.extend ({def}) ->
else
@context.$(siblings.get(index)).before(content)
- debugger if window.DEBUG
@sorting = @sortedModels()
+ # @::insertItem.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def removeItem: (item) ->
if @contents[item.cid]
@@ -62,6 +96,13 @@ AS.Binding.Many = AS.Binding.extend ({def}) ->
delete @bindingGroups[item.cid]
@sorting = @sortedModels()
+ # @::removeItem.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def moveItem: (item) ->
content = @contents[item.cid]
@@ -73,6 +114,13 @@ AS.Binding.Many = AS.Binding.extend ({def}) ->
@context.$(siblings[newIndex]).after(content)
else if newIndex < currentIndex
@context.$(siblings[newIndex]).before(content)
+ # @::moveItem.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def changeItem: (item) ->
if @options.order_by and @sorting.indexOf(item).value() isnt @sortedModels().indexOf(item).value()
@@ -83,6 +131,13 @@ AS.Binding.Many = AS.Binding.extend ({def}) ->
@removeItem(item)
else if @contents[item.cid] is undefined
@insertItem(item)
+ # @::changeItem.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def makeItemContent: (item) ->
return unless item
@@ -103,7 +158,21 @@ AS.Binding.Many = AS.Binding.extend ({def}) ->
@contents[item.cid] = content
return content
+ # @::makeItemContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def makeContent: ->
AS.Binding.Container.new(@container[0])
+ # @::makeContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
30 src/alpha_simprini/client/binding/model.coffee
@@ -2,6 +2,13 @@ AS.Binding.Model = AS.Object.extend ({def}) ->
def initialize: (@context, @model, @content=$([])) ->
@styles = {}
@attrs = {}
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def css: (properties) ->
for property, options of properties
@@ -17,6 +24,13 @@ AS.Binding.Model = AS.Object.extend ({def}) ->
@styles[property] = => options.fn(@model)
painter = => @content.css property, @styles[property]()
@context.binds @model, options.field, painter, this
+ # @::css.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def attr: (attrs) ->
for property, options of attrs
@@ -53,6 +67,13 @@ AS.Binding.Model = AS.Object.extend ({def}) ->
@content.attr property, @attrs[property]()
@context.binds @model, options.field, painter, this
+ # @::attr.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def paint: ->
attrs = {}
@@ -63,5 +84,10 @@ AS.Binding.Model = AS.Object.extend ({def}) ->
@content.attr attrs
@content.css styles
- @content.width @width_fn() if @width_fn
- @content.height @height_fn() if @height_fn
+ # @::paint.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
14 src/alpha_simprini/client/binding/one.coffee
@@ -1,6 +1,13 @@
AS.Binding.One = AS.Binding.Field.extend ({delegate, include, def, defs}) ->
def makeContent: ->
AS.Binding.Container.new(@container[0])
+ # @::makeContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def setContent: ->
@content.empty()
@@ -11,3 +18,10 @@ AS.Binding.One = AS.Binding.Field.extend ({delegate, include, def, defs}) ->
@context.withinBindingGroup @bindingGroup, =>
@context.withinNode @content, =>
@fn.call(@context, value, AS.Binding.Model.new(@context, @model, @container))
+ # @::setContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
30 src/alpha_simprini/client/binding/select.coffee
@@ -2,6 +2,13 @@ AS.Binding.Select = AS.Binding.Input.extend ({def}) ->
def initialize: ->
@_super.apply(this, arguments)
@require_option "options"
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def makeContent: ->
@select?.remove()
@@ -13,17 +20,22 @@ AS.Binding.Select = AS.Binding.Input.extend ({def}) ->
else
for key, value of options
@option value: value, -> key
+ # @::makeContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def setContent: () ->
fieldValue = @fieldValue()
fieldValue = fieldValue.id if fieldValue?.id
@content.val fieldValue
-
- def setField: ->
- value = @select.val()
- value = if _.isArray value then value[0] else value
-
- if _.isArray @field
- @model.writePath @field, value
- else
- @field.set value
+ # @::setCantent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
49 src/alpha_simprini/client/binding_group.coffee
@@ -4,15 +4,41 @@ AS.BindingGroup = AS.Object.extend ({def}) ->
@namespace = _.uniqueId("bg")
@children = []
@boundObjects = []
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
# Unbind all bindings, and then unbind all children binding groups
def unbind: ->
object.unbind("."+@namespace) for object in @boundObjects
@unbindChildren()
+ # @::unbind.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def unbindChildren: ->
- child.unbind() for child in @children
+ for child in @children
+ # target view children for removal from their parent
+ # if child instanceof AS.View
+
+ # else
+ child.unbind()
@children = []
+ # @::unbindChildren.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def binds: (object, event, handler, context) ->
@boundObjects.push object
@@ -27,9 +53,30 @@ AS.BindingGroup = AS.Object.extend ({def}) ->
namespace: @namespace
handler: handler
context: context
+ # @::binds.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def addChild: (child=AS.BindingGroup.new(this))->
@children.push child
return child
+ # @::addChild.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def removeChild: (bindingGroup) -> @children = _(@children).without(bindingGroup)
+ # @::removeChild.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
49 src/alpha_simprini/client/dom.coffee
@@ -32,17 +32,45 @@ AS.DOM = AS.Object.extend ({delegate, include, def, defs}) ->
# TODO: DOUBLE EXPRESS VERIFY THIS ASSUMPTION AND PASTE
# LINKS TO SUPPORTING EVIDENCE IN THE CODE.
@currentNode.appendChild document.createTextNode(textContent)
+ # @::text.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def raw: (html) ->
@$(@span()).html(html)
+ # @::raw.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def tag: (name, attrs, content) ->
node = document.createElement(name)
return @_tag node, attrs, content
+ # @::tag.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def svgTag: (name, attrs, content) ->
node = document.createElementNS(SVG.ns, name)
return @_tag node, attrs, content
+ # @::svgTag.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def _tag: (node, attrs, content) ->
@currentNode ?= document.createDocumentFragment()
@@ -70,6 +98,13 @@ AS.DOM = AS.Object.extend ({delegate, include, def, defs}) ->
@text(last) if _.isString(last)
return node
+ # @::_tag.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def withinNode: (node, fn) ->
node = node[0] if node?.jquery
@@ -78,8 +113,22 @@ AS.DOM = AS.Object.extend ({delegate, include, def, defs}) ->
content = fn.call(this)
@currentNode = priorNode
content
+ # @::withinNode.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def danglingContent: (fn) -> @withinNode(null, fn)
+ # @::danglingContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
DOM_ELEMENTS.each (element) ->
AS.DOM::[element] = -> @tag.apply this, _(arguments).unshift(element)
View
168 src/alpha_simprini/client/models/targets.coffee
@@ -14,40 +14,101 @@ AS.Models.Targets = AS.Object.extend ({def, defs, include}) ->
def initialize: ->
@gather()
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def gather: ->
@targets = $(@selector).map (i, el) ->
return el: $(el), rect: el.getBoundingClientRect()
+ # @::gather.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def validate: () -> true
- # validate: (data) -> true
- # return @element().can_be_parent_for(data.source)
+ # @::validate.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def dropstart: () ->
- return unless @current_hit?.rect
- @trigger("dropstart", @current_hit)
+ return unless @currentHit?.rect
+ @trigger("dropstart", @currentHit)
+ # @::dropstart.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def dropend: () ->
@trigger("dropend")
+ # @::dropend.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def drop: (event) ->
+ # @::drop.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def dragend: (event) ->
- return unless @current_hit?.rect
+ return unless @currentHit?.rect
@drop(event)
- @trigger("drop", @current_hit)
+ @trigger("drop", @currentHit)
+ # @::dragend.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
- def transition_hit: (hit) ->
+ def transitionHit: (hit) ->
return @dropend() if hit is null
- @current_hit ?= AS.Models.Targets.Hit.new()
+ @currentHit ?= AS.Models.Targets.Hit.new()
# Nothin' changed, eh?
- return if @current_hit.equals(hit) or hit.rect is undefined
+ return if @currentHit.equals(hit) or hit.rect is undefined
@dropend()
- @current_hit = hit
+ @currentHit = hit
@dropstart()
+ # @::transitionHit.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def drag: (event) ->
throw "Drag unimplimented in base class!"
+ # @::drag.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
AS.Models.Targets.TOP = TOP
AS.Models.Targets.MIDDLE = MIDDLE
@@ -59,8 +120,15 @@ AS.Models.Targets.Edge = AS.Models.Targets.extend ({def}) ->
def initialize: (options={}) ->
@_super()
@edge = options.edge or 30
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
- def horizontal_target: (event) ->
+ def horizontalTarget: (event) ->
{clientX, clientY} = event["jquery/event"].originalEvent
for target in @targets
rect = target.rect
@@ -76,9 +144,15 @@ AS.Models.Targets.Edge = AS.Models.Targets.extend ({def}) ->
return null unless edge
return AS.Models.Targets.Hit.new target.rect, target.el, edge
+ # @::horizontalTarget.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
-
- def vertical_target: (event) ->
+ def verticalTarget: (event) ->
{clientX, clientY} = event["jquery/event"].originalEvent
for target in @targets
@@ -95,35 +169,69 @@ AS.Models.Targets.Edge = AS.Models.Targets.extend ({def}) ->
return null unless edge
return AS.Models.Targets.Hit.new target.rect, target.el, edge
-
+ # @::verticalTarget.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
AS.Models.Targets.Thirds = AS.Models.Targets.extend ({def}) ->
- def within_vertically: (y, rect) ->
+ def withinVertically: (y, rect) ->
rect.top <= y <= rect.bottom
+ # @::withinVertically.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
- def which_third: (y, rect) ->
- # pre-supposes within_vertically is true
- one_third = rect.height / 3
+ def whichThird: (y, rect) ->
+ # pre-supposes withinVertically is true
+ oneThird = rect.height / 3
offset = y - rect.top
- if offset <= one_third
+ if offset <= oneThird
@TOP
- else if offset <= one_third * 2
+ else if offset <= oneThird * 2
@MIDDLE
else
@BOTTOM
+ # @::whichThird.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def target: (event) ->
{clientY} = event["jquery/event"].originalEvent
for target in @targets
- if @within_vertically(clientY, target.rect)
- hit = AS.Models.Targets.Hit.new(target.rect, target.el, @which_third(clientY, target.rect), event)
+ if @withinVertically(clientY, target.rect)
+ hit = AS.Models.Targets.Hit.new(target.rect, target.el, @whichThird(clientY, target.rect), event)
return hit if @validate(hit)
return null
+ # @::target.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def drag: (event) ->
- @transition_hit @target(event)
+ @transitionHit @target(event)
+ # @::drag.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
AS.Models.Targets.Hit = AS.Object.extend ({def}) ->
def TOP: TOP
@@ -132,6 +240,20 @@ AS.Models.Targets.Hit = AS.Object.extend ({def}) ->
def LEFT: LEFT
def RIGHT: RIGHT
def initialize: (@rect=null, @el=null, @section=null, @event) ->
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def equals: (other=AS.Models.Targets.Hit.new()) ->
other.el is @el and other.section is @section
+ # @::equals.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
187 src/alpha_simprini/client/view.coffee
@@ -17,6 +17,14 @@ AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
baseAttributes["id"] = undefined if @el.attr("id")
@el.attr(baseAttributes)
@el.data().view = this
+ # @::_ensureElement.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
+
def initialize: (config={}) ->
config.el = @$(config.el) if config.el and !(config.el.jquery)
@@ -40,11 +48,32 @@ AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
@delegateEvents()
@bindAttrs()
@runCallbacks "afterContent"
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def content: ->
# Make your content here.
+ # @::content.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def append: (view) -> @el.append view.el
+ # @::append.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def processAttr: (node, key, value) ->
# if value instanceof Function
@@ -55,9 +84,23 @@ AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
# # false
# else
node.setAttribute(key, value)
+ # @::processAttr.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def groupBindings: (fn) ->
@withinBindingGroup @bindingGroup.addChild(), fn
+ # @::groupBindings.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def withinBindingGroup: (bindingGroup, fn) ->
currentGroup = @bindingGroup
@@ -65,8 +108,22 @@ AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
content = fn.call(this, bindingGroup)
@bindingGroup = currentGroup
content
+ # @::withinBindingGroup.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def binds: -> @bindingGroup.binds.apply(@bindingGroup, arguments)
+ # @::binds.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def klassString: ->
classes = []
@@ -75,14 +132,35 @@ AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
classes.push ancestor._name()
classes.join(" ")
+ # @::klassString.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def baseAttributes: ->
attrs =
class: @klassString()
id: @objectId()
+ # @::baseAttributes.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def buildElement: ->
@currentNode = @[@tagName]()
+ # @::buildElement.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def view: (constructor, options={}) ->
options.application = @application
@@ -92,6 +170,13 @@ AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
@bindingGroup.addChild(view)
@currentNode?.appendChild view.el[0]
view.el[0]
+ # @::view.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def descendantViews: (views=[], constructor) ->
for view in @childViews
@@ -102,29 +187,71 @@ AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
view.descendantViews(views, constructor)
views
+ # @::descendantViews.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def removeChild: (child) ->
@childViews = _.without(@childViews, child)
+ # @::removeChild.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
# DO NOT OVERRIDE #unbind
+ # find out why, AND MENTION IT HERE
+ # because ANY event unbinding will remove the child view
def unbind: ->
# AS.warn("Do not OVERRIDE View.unbind")
@_super.apply(this, arguments)
- # @parentView?.removeChild(this)
- # @el.remove()
+ # @::unbind.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def binding: (bindable, options, fnOrElement) ->
if bindable instanceof AS.Collection or bindable instanceof AS.Model.HasMany.Instance
AS.Binding.Many.new(this, bindable, bindable, options, fnOrElement)
else if bindable instanceof AS.Model
AS.Binding.Model.new(this, bindable, options or fnOrElement)
+ # @::binding.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def modelBinding: ->
@_modelBinding ?= AS.Binding.Model.new(this, @model, @el)
+ # @::modelBinding.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def bindAttrs: ->
return unless @attrBindings
@modelBinding().attr @attrBindings
+ # @::bindAttrs.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def delegateEvents: () ->
if @events
@@ -145,6 +272,13 @@ AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
@["enter_#{state}"] = ->
@trigger("enterstate:#{state}")
@stateEvents[state].applyBindings()
+ # @::delegateEvents.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
# TODO: put these into modules or something.
def pluralize: (thing, count) ->
@@ -153,34 +287,45 @@ AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
else
fleck.pluralize(thing)
- def reset_cycle: (args...) ->
+ # @::pluralize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
+
+ def resetCycle: (args...) ->
delete @_cycles[args.join()] if @_cycles
+ # @::resetCycle.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def cycle: (args...) ->
@_cycles ?= {}
@_cycles[args.join()] ?= 0
count = @_cycles[args.join()] += 1
args[count % args.length]
+ # @::cycle.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def toggle: ->
@button class:"toggle expand"
@button class:"toggle collapse"
-
- def field: (_label, options = {}, fn = ->) ->
- if _.isFunction options
- fn = options
- options = {}
-
- @div ->
- @label _label
- @input(options)
- fn?.call(this)
-
- def choice: (_label, options = {}, fn = ->) ->
- if _.isFunction options
- fn = options
- options = {}
- options.type = "checkbox"
-
- @field _label, options, fn
+ # @::toggle.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
56 src/alpha_simprini/client/view_events.coffee
@@ -6,6 +6,13 @@ AS.ViewEvents = AS.Object.extend ({def}) ->
@events = @unifyOptions(events)
@validateOptions()
@cacheHandlers()
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def unifyOptions: (events) ->
for key, options of events
@@ -20,6 +27,13 @@ AS.ViewEvents = AS.Object.extend ({def}) ->
return events
+ # @::unifyOptions.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def validateOptions: ->
for key, options of @events
@@ -45,6 +59,13 @@ AS.ViewEvents = AS.Object.extend ({def}) ->
Specified method for event #{key} that is not a function.
Specify only a function as a method for an event handler.
"""
+ # @::validateOptions.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def cacheHandlers: ->
for key, options of @events
@@ -55,9 +76,23 @@ AS.ViewEvents = AS.Object.extend ({def}) ->
options.method.apply(@view, arguments)
else if options.transition
@view.transitionState options.transition
+ # @::cacheHandlers.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def revokeBindings: ->
@revokeBinding(options) for key, options of @events
+ # @::revokeBindings.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def revokeBinding: (options) ->
[selector, eventName] = [options.selector, options.eventName]
@@ -71,9 +106,23 @@ AS.ViewEvents = AS.Object.extend ({def}) ->
target = @view.$(selector, @view.el[0])
target.off @namespace
target.click() # bug with drag/drop allows for one last drag after revoking bindings :(
+ # @::revokeBinding.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def applyBindings: ->
@applyBinding(options) for key, options of @events
+ # @::applyBindings.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def applyBinding: (options) ->
[selector, eventName, handler] = [options.selector, options.eventName, options.handler]
@@ -92,3 +141,10 @@ AS.ViewEvents = AS.Object.extend ({def}) ->
else
selector = selector.replace /\$/g, "#"+@view.el.attr('id')
@view.el.delegate selector, eventName, handler
+ # @::applyBinding.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
49 src/alpha_simprini/client/view_model.coffee
@@ -40,24 +40,73 @@ AS.ViewModel = AS.Object.extend ({delegate, include, def, defs}) ->
@model.bind("change:id", (=> @id = @model.id))
for key, config of @model.constructor.properties
@[key] = @model[key]
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def binding: (field, options, fn) ->
if _.isFunction(options)
[fn, options] = [options, {}]
@constructor.bindables[field].new(@view, @model, @model[field], options, fn)
+ # @::binding.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def input: (field, options) ->
AS.Binding.Input.new(@view, @model, field, options)
+ # @::input.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def file: (field, options) ->
AS.Binding.File.new(@view, @model, field, options)
+ # @::file.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def checkbox: (field, options) ->
AS.Binding.CheckBox.new(@view, @model, field, options)
+ # @::checkbox.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def select: (field, options) ->
AS.Binding.Select.new(@view, @model, field, options)
+ # @::select.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def editline: (field, options) ->
AS.Binding.EditLine.new(@view, @model, field, options)
+ # @::editline.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
1  src/alpha_simprini/client/views/canvas.coffee
@@ -1 +0,0 @@
-class AS.Views.Canvas extends AS.Views.Panel
View
111 src/alpha_simprini/client/views/dialog.coffee
@@ -4,50 +4,137 @@ AS.Views.Dialog = AS.Views.Panel.extend ({delegate, include, def, defs}) ->
def initialize: ->
@constructor::events ?= {}
_.extend @constructor::events,
- "click .accept": "trigger_commit"
- "click .cancel": "trigger_cancel"
- "esc @application": "trigger_cancel"
- "accept @application": "trigger_commit"
+ "click .accept": "triggerCommit"
+ "click .cancel": "triggerCancel"
+ "esc @application": "triggerCancel"
+ "accept @application": "triggerCommit"
"knead:dragstart header": "dragstart"
"knead:drag header": "drag"
"knead:dragend header": "dragend"
@_super.apply(this, arguments)
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def content: ->
- @head = @$ @header @header_content
- @content = @$ @section @main_content
- @foot = @$ @footer @footer_content
+ @head = @$ @header @headerContent
+ @content = @$ @section @mainContent
+ @foot = @$ @footer @footerContent
knead.monitor @head
+ # @::content.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
- def header_content: ->
- def main_content: ->
- def footer_content: ->
+ def headerContent: ->
+ # @::headerContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
+ def mainContent: ->
+ # @::mainContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
+ def footerContent: ->
@accept = @$ @button class:"accept", -> "Accept"
@cancel = @$ @a href:"#", class:"cancel", -> "cancel"
+ # @::footerContent.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def open: ->
@el.css width: "", height: ""
@trigger "open"
+ # @::open.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def close: ->
@el.css width: 0, height: 0, overflow: "hidden"
@trigger "close"
+ # @::close.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
- def trigger_commit: ->
+ def triggerCommit: ->
@trigger "commit"
@close()
+ # @::triggerCommit.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
- def trigger_cancel: ->
+ def triggerCancel: ->
@trigger "cancel"
@close()
+ # @::triggerCancel.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
+
def dragstart: (event) ->
@start = @el.position()
+ # @::dragstart.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
+
def drag: (event) ->
@el.css
top: event.deltaY + @start.top
left: event.deltaX + @start.left
+ # @::drag.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
+
def dragend: (event) ->
delete @start
+ # @::dragend.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
36 src/alpha_simprini/client/views/region.coffee
@@ -4,13 +4,35 @@ AS.Views.Region = AS.View.extend ({def}) ->
def initialize: ->
@_super.apply this, arguments
@application?.bind "resize", => @layout()
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
def layout: ->
+ # @::layout.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
+
AS.Views.North = AS.Views.Region.extend ({def}) ->
AS.Views.East = AS.Views.Region.extend ({def}) ->
def layout: ->
@el.css
top: @el.siblings(".North").outerHeight() or 0
bottom: @el.siblings(".South").outerHeight() or 0
+ # @::layout.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
AS.Views.South = AS.Views.Region.extend ({def}) ->
AS.Views.West = AS.Views.Region.extend ({def}) ->
@@ -18,6 +40,13 @@ AS.Views.West = AS.Views.Region.extend ({def}) ->
@el.css
top: @el.siblings(".North").outerHeight() or 0
bottom: @el.siblings(".South").outerHeight() or 0
+ # @::layout.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
AS.Views.Center = AS.Views.Region.extend ({def}) ->
def layout: ->
@@ -26,3 +55,10 @@ AS.Views.Center = AS.Views.Region.extend ({def}) ->
bottom: @el.siblings(".South").outerHeight() or 0
left: @el.siblings(".West").outerWidth() or 0
right: @el.siblings(".East").outerWidth() or 0
+ # @::layout.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
9 src/alpha_simprini/client/views/stage.coffee
@@ -3,4 +3,11 @@ AS.Views.Stage = AS.Views.Panel.extend ({delegate, include, def, defs}) ->
def initialize: (config) ->
@_super.apply(this, arguments)
@canvas ?= AS.Views.Canvas.new()
- @el.append @canvas.el
+ @el.append @canvas.el
+ # @::initialize.doc =
+ # params: [
+ # []
+ # ]
+ # desc: """
+ #
+ # """
View
7 src/alpha_simprini/core/callbacks.coffee
@@ -8,6 +8,13 @@ AS.Callbacks = AS.Module.extend ({def, defs}) ->
do (callback) =>
@["#{key}#{upperCamelize callback}"] = (fn) ->
@pushInheritableItem("#{key}#{upperCamelize callback}_callbacks", fn)
+ # @defineCallbacks.doc =
+ # params: [
+ # ["all"]
+ # ]
+ # desc: """
+ #
+ # """
def runCallbacks: (name) ->
for callback in @constructor["#{name}_callbacks"] || []
View
7 src/alpha_simprini/core/model.coffee
@@ -2,6 +2,8 @@
AS.All = byCid: {}, byId: {}, byIdRef: {}
+makeIdRef = (id, constructor) -> "#{id}-#{constructor.path()}"
+
AS.Model = AS.Object.extend ({delegate, include, def, defs}) ->
include Taxi.Mixin
include AS.Callbacks
@@ -15,7 +17,8 @@ AS.Model = AS.Object.extend ({delegate, include, def, defs}) ->
]
defs find: (id) ->
- AS.All.byId[id] or @new(id:id)
+ idRef = makeIdRef(id, this)
+ AS.All.byIdRef[idRef] or @new(id:id)
# @find.doc =
# params: [
# ["id", String, true]
@@ -69,7 +72,7 @@ AS.Model = AS.Object.extend ({delegate, include, def, defs}) ->
delete AS.All.byIdRef["#{@id}-#{@constructor.path()}"]
@id = id
- @idRef = "#{@id}-#{@constructor.path()}"
+ @idRef = makeIdRef(@id, @constructor)
# NEVER CHANGE THE CID
@cid ?= @idRef or uniqueId("c")
View
3  src/alpha_simprini/core/model/rest.coffee
@@ -78,7 +78,8 @@ AS.Model.REST = AS.Module.extend ({delegate, include, def, defs}) ->
@constructor.mappings()[key].sideloadData(embed, references) for embed in embeds
references.each (model, ids) -> model.resolveReferences(ids)
- @trigger("ready")
+ references.each (model) -> model.trigger("ready")
+ # @trigger("ready")
return this
defs sideloadData: (modelData, references) ->
View
2  src/alpha_simprini/core/models/file.coffee
@@ -117,7 +117,7 @@ AS.Models.File = AS.Model.extend ({delegate, include, def, defs}) ->
data: formdata
processData: false
contentType: false
- error: => require("alpha_simprini").error("POST /images failed", this)
+ error: => AS.error("POST /images failed", this)
success: (data, status, xhr) =>
@url.set xhr.getResponseHeader("Location")
@trigger("uploaded")
View
10 test/client/binding/check_box.coffee
@@ -27,4 +27,12 @@ test "unchecking the box sets the field to false", ->
[mocks, binding] = mockBinding(AS.Binding.CheckBox, model: model, field: model.maybe)
binding.content.click().trigger("change")
equal model.maybe.get(), false
-
+
+test "setting the model value checks/unchecks the box", ->
+ model = BoundModel.new maybe: true
+ [mocks, binding] = mockBinding(AS.Binding.CheckBox, model: model, field: model.maybe)
+ equal binding.content.parent().find(":checked").length, 1, 'starts out checked'
+ model.maybe.set false
+ equal binding.content.parent().find(":checked").length, 0, 'unchecks properly'
+ model.maybe.set true
+ equal binding.content.parent().find(":checked").length, 1, 'rechecks properly'
View
30 test/client/models/targets.coffee
@@ -56,7 +56,7 @@ test "dropend triggers dropend event", ->
test "dropstart triggers dropstart event if current hit has a rect", ->
targets = NS.SomeTargets.new()
hit = rect: true
- targets.current_hit = hit
+ targets.currentHit = hit
expect 1
targets.bind "dropstart", (thehit) -> equal hit, thehit
targets.dropstart()
@@ -71,7 +71,7 @@ test "dragend calls drop and triggers drop if current hit has a rect", ->
targets = NS.SomeTargets.new()
hit = rect: true
data = new Object
- targets.current_hit = hit
+ targets.currentHit = hit
expect 2
targets.bind "drop", (thehit) -> equal hit, thehit
targets.drop = (thedata) -> equal thedata, data
@@ -89,28 +89,28 @@ test "noop if hit has no rect", ->
targets = NS.SomeTargets.new()
targets.dropend = -> ok true
expect 0
- targets.transition_hit {}
+ targets.transitionHit {}
test "noop if currenth hit equals hit", ->
targets = NS.SomeTargets.new()
- targets.current_hit = equals: -> true
+ targets.currentHit = equals: -> true
targets.dropend = -> ok true
expect 0
- targets.transition_hit {}
+ targets.transitionHit {}
test "transitions if current hit does not equal hit", ->
targets = NS.SomeTargets.new()
- targets.current_hit = equals: -> false
+ targets.currentHit = equals: -> false
hit = rect: true
expect 2
targets.dropend = ->
- ok targets.current_hit isnt hit
+ ok targets.currentHit isnt hit
targets.dropstart = ->
- ok targets.current_hit is hit
- targets.transition_hit hit
+ ok targets.currentHit is hit
+ targets.transitionHit hit
-target_event = (x, y) ->
+targetEvent = (x, y) ->
return {
"jquery/event": originalEvent:
clientX: x
@@ -127,11 +127,11 @@ setupEdgeTargets = ->
rect: @rect
]
-module "Targets.Edge.vertical_target",
+module "Targets.Edge.verticalTarget",
setup: ->
setupEdgeTargets.call(this)
@check = (x, y) =>
- @targets.vertical_target target_event(x, y)
+ @targets.verticalTarget targetEvent(x, y)
test "misses when not inside box", ->
equal null, @check(-1, -1), "before"
@@ -150,11 +150,11 @@ test "hits TOP/BOTTOM", ->
hit = @check(0, 50)
equal hit.section, hit.BOTTOM
-module "Targets.Edge.horizontal_target",
+module "Targets.Edge.horizontalTarget",
setup: ->
setupEdgeTargets.call(this)
@check = (x, y) =>
- @targets.horizontal_target target_event(x, y)
+ @targets.horizontalTarget targetEvent(x, y)
test "misses when not inside box", ->
equal null, @check(-1, -1), "before"
@@ -185,7 +185,7 @@ module "Targets.Thirds",
]
@check = (x, y) =>
- @targets.target target_event(x, y)