joosy 0.1.0.RC3 → 0.1.0.alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +0 -2
- data/Gemfile +2 -13
- data/Gemfile.lock +62 -80
- data/Guardfile +15 -21
- data/MIT-LICENSE +2 -2
- data/README.rdoc +3 -0
- data/app/helpers/joosy/sprockets_helper.rb +11 -23
- data/joosy.gemspec +3 -3
- data/lib/joosy/forms.rb +12 -2
- data/lib/joosy/rails/engine.rb +1 -9
- data/lib/joosy/rails/version.rb +2 -2
- data/lib/joosy-rails.rb +5 -0
- data/lib/rails/generators/joosy/application_generator.rb +3 -13
- data/lib/rails/generators/joosy/joosy_base.rb +2 -2
- data/lib/rails/generators/joosy/layout_generator.rb +1 -8
- data/lib/rails/generators/joosy/page_generator.rb +6 -21
- data/lib/rails/generators/joosy/preloader_generator.rb +7 -14
- data/lib/rails/generators/joosy/templates/app/layouts/application.js.coffee +0 -1
- data/lib/rails/generators/joosy/templates/app/layouts/template.js.coffee +1 -1
- data/lib/rails/generators/joosy/templates/app/pages/application.js.coffee +1 -1
- data/lib/rails/generators/joosy/templates/app/pages/template.js.coffee +3 -3
- data/lib/rails/generators/joosy/templates/app/routes.js.coffee +1 -7
- data/lib/rails/generators/joosy/templates/app/widgets/template.js.coffee +2 -2
- data/lib/rails/generators/joosy/templates/app.js.coffee +0 -3
- data/lib/rails/generators/joosy/templates/app_preloader.js.coffee.erb +12 -9
- data/lib/rails/generators/joosy/templates/preload.html.erb +6 -5
- data/lib/rails/generators/joosy/templates/preload.html.haml +5 -3
- data/lib/rails/generators/joosy/templates/preload.html.slim +21 -0
- data/lib/rails/generators/joosy/widget_generator.rb +1 -8
- data/spec/javascripts/helpers/spec_helper.js.coffee +0 -20
- data/spec/javascripts/joosy/core/modules/container_spec.js.coffee +27 -24
- data/spec/javascripts/joosy/core/modules/events_spec.js.coffee +18 -42
- data/spec/javascripts/joosy/core/modules/filters_spec.js.coffee +27 -27
- data/spec/javascripts/joosy/core/modules/log_spec.js.coffee +3 -3
- data/spec/javascripts/joosy/core/modules/module_spec.js.coffee +15 -6
- data/spec/javascripts/joosy/core/modules/time_manager_spec.js.coffee +7 -12
- data/spec/javascripts/joosy/core/modules/widget_manager_spec.js.coffee +17 -31
- data/tmp/javascripts/.gitignore +1 -0
- data/tmp/spec/javascripts/helpers/.gitignore +1 -0
- data/vendor/assets/javascripts/base64.js +135 -0
- data/vendor/assets/javascripts/joosy/core/application.js.coffee +26 -0
- data/vendor/assets/javascripts/joosy/core/form.js.coffee +87 -0
- data/vendor/assets/javascripts/joosy/core/joosy.js.coffee +62 -0
- data/vendor/assets/javascripts/joosy/core/layout.js.coffee +38 -0
- data/vendor/assets/javascripts/joosy/core/modules/container.js.coffee +51 -0
- data/vendor/assets/javascripts/joosy/core/modules/events.js.coffee +17 -0
- data/vendor/assets/javascripts/joosy/core/modules/filters.js.coffee +39 -0
- data/vendor/assets/javascripts/joosy/core/modules/log.js.coffee +12 -0
- data/vendor/assets/javascripts/joosy/core/modules/module.js.coffee +28 -0
- data/vendor/assets/javascripts/joosy/core/modules/time_manager.js.coffee +23 -0
- data/vendor/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +45 -0
- data/vendor/assets/javascripts/joosy/core/page.js.coffee +136 -0
- data/vendor/assets/javascripts/joosy/core/resource/rest.js.coffee +69 -0
- data/vendor/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +42 -0
- data/vendor/assets/javascripts/joosy/core/router.js.coffee +75 -0
- data/vendor/assets/javascripts/joosy/core/widget.js.coffee +35 -0
- data/vendor/assets/javascripts/joosy/preloader/development.js.coffee +27 -0
- data/vendor/assets/javascripts/joosy/preloader/production.js.coffee +84 -0
- data/{app → vendor}/assets/javascripts/joosy.js.coffee +0 -0
- data/vendor/assets/javascripts/jquery.form.js +963 -978
- data/vendor/assets/javascripts/sugar.js +1 -1
- metadata +48 -77
- data/.codoopts +0 -5
- data/README.md +0 -95
- data/app/assets/javascripts/joosy/core/application.js.coffee +0 -50
- data/app/assets/javascripts/joosy/core/form.js.coffee +0 -304
- data/app/assets/javascripts/joosy/core/helpers/view.js.coffee +0 -30
- data/app/assets/javascripts/joosy/core/joosy.js.coffee +0 -129
- data/app/assets/javascripts/joosy/core/layout.js.coffee +0 -162
- data/app/assets/javascripts/joosy/core/modules/container.js.coffee +0 -104
- data/app/assets/javascripts/joosy/core/modules/events.js.coffee +0 -123
- data/app/assets/javascripts/joosy/core/modules/filters.js.coffee +0 -67
- data/app/assets/javascripts/joosy/core/modules/log.js.coffee +0 -36
- data/app/assets/javascripts/joosy/core/modules/module.js.coffee +0 -105
- data/app/assets/javascripts/joosy/core/modules/renderer.js.coffee +0 -195
- data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +0 -46
- data/app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +0 -84
- data/app/assets/javascripts/joosy/core/page.js.coffee +0 -375
- data/app/assets/javascripts/joosy/core/preloader.js.coffee +0 -13
- data/app/assets/javascripts/joosy/core/resource/collection.js.coffee +0 -174
- data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +0 -254
- data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +0 -197
- data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +0 -125
- data/app/assets/javascripts/joosy/core/router.js.coffee +0 -163
- data/app/assets/javascripts/joosy/core/templaters/rails_jst.js.coffee +0 -36
- data/app/assets/javascripts/joosy/core/widget.js.coffee +0 -80
- data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +0 -169
- data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +0 -56
- data/lib/joosy.rb +0 -9
- data/lib/rails/generators/joosy/resource_generator.rb +0 -29
- data/lib/rails/generators/joosy/templates/app/helpers/application.js.coffee +0 -4
- data/lib/rails/generators/joosy/templates/app/pages/welcome/index.js.coffee +0 -22
- data/lib/rails/generators/joosy/templates/app/resources/template.js.coffee +0 -2
- data/lib/rails/generators/joosy/templates/app/templates/layouts/application.jst.hamlc +0 -2
- data/lib/rails/generators/joosy/templates/app/templates/pages/welcome/index.jst.hamlc +0 -7
- data/spec/javascripts/joosy/core/application_spec.js.coffee +0 -40
- data/spec/javascripts/joosy/core/form_spec.js.coffee +0 -184
- data/spec/javascripts/joosy/core/joosy_spec.js.coffee +0 -72
- data/spec/javascripts/joosy/core/layout_spec.js.coffee +0 -50
- data/spec/javascripts/joosy/core/modules/renderer_spec.js.coffee +0 -185
- data/spec/javascripts/joosy/core/page_spec.js.coffee +0 -178
- data/spec/javascripts/joosy/core/resource/collection_spec.js.coffee +0 -84
- data/spec/javascripts/joosy/core/resource/generic_spec.js.coffee +0 -118
- data/spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee +0 -58
- data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +0 -129
- data/spec/javascripts/joosy/core/router_spec.js.coffee +0 -123
- data/spec/javascripts/joosy/core/templaters/rails_jst_spec.js.coffee +0 -25
- data/spec/javascripts/joosy/core/widget_spec.js.coffee +0 -40
- data/spec/javascripts/joosy/preloaders/caching_spec.js.coffee +0 -36
- data/spec/javascripts/joosy/preloaders/inline_spec.js.coffee +0 -16
- data/spec/javascripts/support/assets/coolface.jpg +0 -0
- data/spec/javascripts/support/assets/okay.jpg +0 -0
- data/spec/javascripts/support/assets/test.js +0 -1
- data/spec/javascripts/support/sinon-ie-1.3.1.js +0 -82
- data/vendor/assets/javascripts/metamorph.js +0 -409
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
#= require joosy/core/joosy
|
|
2
|
-
#= require joosy/core/modules/module
|
|
3
|
-
#= require joosy/core/modules/log
|
|
4
|
-
#= require joosy/core/modules/events
|
|
5
|
-
#= require joosy/core/modules/container
|
|
6
|
-
|
|
7
|
-
#
|
|
8
|
-
# AJAXifies form including file uploads and stuff. Built on top of jQuery.Form.
|
|
9
|
-
#
|
|
10
|
-
# Joosy.Form automatically cares of form validation hihglights. It can
|
|
11
|
-
# read common server error responses and add .field_with_errors class to proper
|
|
12
|
-
# field.
|
|
13
|
-
#
|
|
14
|
-
# If you don't have resource associated with form (#fill), it will try to find fields
|
|
15
|
-
# by exact keywords from response. Otherwise it will search for resource_name[field].
|
|
16
|
-
#
|
|
17
|
-
# @example Joosy.Form usage
|
|
18
|
-
# form = new Joosy.Form, -> (response)
|
|
19
|
-
# console.log "Saved and got some: #{response}"
|
|
20
|
-
#
|
|
21
|
-
# form.progress = (percent) -> console.log "Uploaded by #{percent}%"
|
|
22
|
-
# form.fill @resource
|
|
23
|
-
#
|
|
24
|
-
class Joosy.Form extends Joosy.Module
|
|
25
|
-
@include Joosy.Modules.Log
|
|
26
|
-
@include Joosy.Modules.Events
|
|
27
|
-
@include Joosy.Modules.Container
|
|
28
|
-
|
|
29
|
-
#
|
|
30
|
-
# Marks the CSS class to use to mark invalidated fields
|
|
31
|
-
#
|
|
32
|
-
invalidationClass: 'field_with_errors'
|
|
33
|
-
|
|
34
|
-
#
|
|
35
|
-
# List of mappings for fields of invalidated data which comes from server
|
|
36
|
-
#
|
|
37
|
-
# If you have something like {foo: 'bar', bar: 'baz'} coming from server
|
|
38
|
-
# substitutions = {foo: 'foo_id'} will change it to {foo_id: 'bar', bar: 'baz'}
|
|
39
|
-
#
|
|
40
|
-
substitutions: {}
|
|
41
|
-
|
|
42
|
-
#
|
|
43
|
-
# List of elements for internal usage
|
|
44
|
-
#
|
|
45
|
-
elements:
|
|
46
|
-
'fields': 'input,select,textarea'
|
|
47
|
-
|
|
48
|
-
#
|
|
49
|
-
# Makes one AJAX request with form data without binding
|
|
50
|
-
#
|
|
51
|
-
# @see #constructor
|
|
52
|
-
#
|
|
53
|
-
# @param [Element] form Instance of HTML form element
|
|
54
|
-
# @param [Hash] opts Options
|
|
55
|
-
#
|
|
56
|
-
@submit: (form, opts={}) ->
|
|
57
|
-
form = new @(form, opts)
|
|
58
|
-
form.container.submit()
|
|
59
|
-
form.unbind()
|
|
60
|
-
null
|
|
61
|
-
|
|
62
|
-
#
|
|
63
|
-
# During initialization replaces your basic form submit with AJAX request
|
|
64
|
-
#
|
|
65
|
-
# @note If method of form differs from POST or GET it will simulate it
|
|
66
|
-
# by adding hidden _method input. In this cases the method itself will be
|
|
67
|
-
# set to POST.
|
|
68
|
-
#
|
|
69
|
-
# @note For browsers having no support of HTML5 Forms it may do an iframe requests
|
|
70
|
-
# to handle file uploading.
|
|
71
|
-
#
|
|
72
|
-
# @param [jQuery] form Form element instance
|
|
73
|
-
# @param [Hash] opts Options
|
|
74
|
-
#
|
|
75
|
-
# @option opts [Function] before `(XHR) -> Bollean` to trigger right before submit.
|
|
76
|
-
# By default will run form invalidation cleanup. This behavior can be canceled
|
|
77
|
-
# by returning false from your own before callback. Both of callbacks will run if
|
|
78
|
-
# you return true.
|
|
79
|
-
#
|
|
80
|
-
# @option opts [Function] success `(Object) -> null` triggers on 200 HTTP code from server.
|
|
81
|
-
# Pases in the parsed JSON.
|
|
82
|
-
#
|
|
83
|
-
# @option opts [Function] progress `(Float) -> null` runs periodically while form is uploading
|
|
84
|
-
#
|
|
85
|
-
# @option opts [Function] error `(Object) -> Boolean` triggers if server responded with anything but 200.
|
|
86
|
-
# By default will run form invalidation routine. This behavior can be canceled
|
|
87
|
-
# by returning false from your own error callback. Both of callbacks will run if
|
|
88
|
-
# you return true.
|
|
89
|
-
#
|
|
90
|
-
constructor: (form, opts={}) ->
|
|
91
|
-
if Object.isFunction opts
|
|
92
|
-
@success = opts
|
|
93
|
-
else
|
|
94
|
-
Object.each opts, (key, value) =>
|
|
95
|
-
@[key] = value
|
|
96
|
-
|
|
97
|
-
@container = $(form)
|
|
98
|
-
@refreshElements()
|
|
99
|
-
@__delegateEvents()
|
|
100
|
-
|
|
101
|
-
method = @container.get(0).getAttribute('method')?.toLowerCase()
|
|
102
|
-
if method && !['get', 'post'].has method
|
|
103
|
-
@__markMethod method
|
|
104
|
-
@container.attr 'method', 'POST'
|
|
105
|
-
|
|
106
|
-
@container.ajaxForm
|
|
107
|
-
dataType: 'json'
|
|
108
|
-
beforeSend: =>
|
|
109
|
-
@__before arguments...
|
|
110
|
-
success: =>
|
|
111
|
-
@__success arguments...
|
|
112
|
-
error: =>
|
|
113
|
-
@__error arguments...
|
|
114
|
-
xhr: =>
|
|
115
|
-
xhr = $.ajaxSettings.xhr()
|
|
116
|
-
if xhr.upload? && @progress
|
|
117
|
-
xhr.upload.onprogress = (event) =>
|
|
118
|
-
if event.lengthComputable
|
|
119
|
-
@progress (event.position / event.total * 100).round 2
|
|
120
|
-
xhr
|
|
121
|
-
|
|
122
|
-
#
|
|
123
|
-
# Resets form submit behavior to default
|
|
124
|
-
#
|
|
125
|
-
unbind: ->
|
|
126
|
-
@container.unbind('submit').find('input:submit,input:image,button:submit').unbind('click');
|
|
127
|
-
|
|
128
|
-
#
|
|
129
|
-
# Links current form with given resource and sets values of form inputs from with it.
|
|
130
|
-
# Form will use give resource while doing invalidation routine.
|
|
131
|
-
#
|
|
132
|
-
# @param [Resource] resource Resource to fill fields with
|
|
133
|
-
# @param [Function] decorator Decoration callback
|
|
134
|
-
#
|
|
135
|
-
fill: (resource, decorator) ->
|
|
136
|
-
@__resource = resource
|
|
137
|
-
|
|
138
|
-
if decorator?
|
|
139
|
-
e = decorator resource.e
|
|
140
|
-
else
|
|
141
|
-
e = resource.e
|
|
142
|
-
Object.each e, (key, val) =>
|
|
143
|
-
key = resource.__entityName + "[#{key}]"
|
|
144
|
-
input = @fields.filter("[name='#{key.underscore()}']:not(:file),[name='#{key.camelize(false)}']:not(:file)")
|
|
145
|
-
unless input.is ':checkbox'
|
|
146
|
-
input.val val
|
|
147
|
-
else
|
|
148
|
-
if val
|
|
149
|
-
input.attr 'checked', 'checked'
|
|
150
|
-
else
|
|
151
|
-
input.removeAttr 'checked'
|
|
152
|
-
|
|
153
|
-
@container.attr 'action', resource.constructor.__buildSource(extension: resource.id)
|
|
154
|
-
@__markMethod() if resource.id
|
|
155
|
-
@container.attr 'method', 'POST'
|
|
156
|
-
|
|
157
|
-
#
|
|
158
|
-
# Submit the HTML Form
|
|
159
|
-
#
|
|
160
|
-
submit: ->
|
|
161
|
-
@container.submit()
|
|
162
|
-
|
|
163
|
-
#
|
|
164
|
-
# Serializes form into query string.
|
|
165
|
-
#
|
|
166
|
-
# @param [Boolean] skipMethod Determines if we should skip magical _method field
|
|
167
|
-
#
|
|
168
|
-
# @return [String]
|
|
169
|
-
#
|
|
170
|
-
serialize: (skipMethod=true) ->
|
|
171
|
-
data = @container.serialize()
|
|
172
|
-
data = data.replace /\&?\_method\=put/i, '' if skipMethod
|
|
173
|
-
|
|
174
|
-
data
|
|
175
|
-
|
|
176
|
-
#
|
|
177
|
-
# Inner success callback.
|
|
178
|
-
#
|
|
179
|
-
__success: (response, status, xhr) ->
|
|
180
|
-
if xhr
|
|
181
|
-
@success? response
|
|
182
|
-
else if response.status == 200
|
|
183
|
-
@success response.json
|
|
184
|
-
else
|
|
185
|
-
@__error response.json
|
|
186
|
-
|
|
187
|
-
#
|
|
188
|
-
# Inner before callback.
|
|
189
|
-
# By default will clean invalidation.
|
|
190
|
-
#
|
|
191
|
-
__before: (xhr, settings) ->
|
|
192
|
-
if !@before? || @before(arguments...) is true
|
|
193
|
-
@fields.removeClass @invalidationClass
|
|
194
|
-
|
|
195
|
-
#
|
|
196
|
-
# Inner error callback.
|
|
197
|
-
# By default will trigger basic invalidation.
|
|
198
|
-
#
|
|
199
|
-
__error: (data) ->
|
|
200
|
-
errors = if data.responseText
|
|
201
|
-
try
|
|
202
|
-
data = jQuery.parseJSON(data.responseText)
|
|
203
|
-
catch error
|
|
204
|
-
{}
|
|
205
|
-
else
|
|
206
|
-
data
|
|
207
|
-
|
|
208
|
-
if !@error? || @error(errors) is true
|
|
209
|
-
errors = @__stringifyErrors(errors)
|
|
210
|
-
|
|
211
|
-
Object.each errors, (field, notifications) =>
|
|
212
|
-
input = @__findField(field).addClass @invalidationClass
|
|
213
|
-
@notification? input, notifications
|
|
214
|
-
|
|
215
|
-
#
|
|
216
|
-
# Finds field by field name.
|
|
217
|
-
# This is not inlined since we want to override
|
|
218
|
-
# or monkeypatch it from time to time
|
|
219
|
-
#
|
|
220
|
-
# @param [String] field Name of field to find
|
|
221
|
-
#
|
|
222
|
-
__findField: (field) ->
|
|
223
|
-
@fields.filter("[name='#{field}']")
|
|
224
|
-
|
|
225
|
-
#
|
|
226
|
-
# Simulates REST methods by adding hidden _method input with real method
|
|
227
|
-
# while setting POST as the transport method
|
|
228
|
-
#
|
|
229
|
-
# @param [String] method Real method to simulate
|
|
230
|
-
#
|
|
231
|
-
__markMethod: (method='PUT') ->
|
|
232
|
-
method = $('<input/>',
|
|
233
|
-
type: 'hidden'
|
|
234
|
-
name: '_method'
|
|
235
|
-
value: method
|
|
236
|
-
)
|
|
237
|
-
@container.append method
|
|
238
|
-
|
|
239
|
-
#
|
|
240
|
-
# Prepares server response for default error handler
|
|
241
|
-
# Turns all possible response notations into form notation (foo[bar])
|
|
242
|
-
# Every direct field of incoming data will be decorated by @substitutions
|
|
243
|
-
#
|
|
244
|
-
# @example Flat validation result
|
|
245
|
-
# { field1: ['error'] } # input
|
|
246
|
-
# { field1: ['error'] } # if form was not associated with Resource by {#fill}
|
|
247
|
-
# { "fluffy[field1]": ['error']} # if form was associated with Resource (named fluffy)
|
|
248
|
-
#
|
|
249
|
-
# @example Complex validation result
|
|
250
|
-
# { foo: { bar: { baz: ['error'] } } } # input
|
|
251
|
-
# { "foo[bar][bar]": ['error'] } # output
|
|
252
|
-
#
|
|
253
|
-
# @param [Object] errors Data to prepare
|
|
254
|
-
#
|
|
255
|
-
# @return [Hash<String, Array>] Flat hash with field names in keys and arrays
|
|
256
|
-
# of errors in values
|
|
257
|
-
#
|
|
258
|
-
__stringifyErrors: (errors) ->
|
|
259
|
-
result = {}
|
|
260
|
-
|
|
261
|
-
Object.each errors, (field, notifications) =>
|
|
262
|
-
if @substitutions[field]?
|
|
263
|
-
field = @substitutions[field]
|
|
264
|
-
|
|
265
|
-
if Object.isObject notifications
|
|
266
|
-
Object.each @__foldInlineEntities(notifications), (key, value) ->
|
|
267
|
-
result[field+key] = value
|
|
268
|
-
else
|
|
269
|
-
if field.indexOf(".") != -1
|
|
270
|
-
splited = field.split '.'
|
|
271
|
-
field = splited.shift()
|
|
272
|
-
field = @__resource.__entityName + "[#{field}]" if @__resource
|
|
273
|
-
field += "[#{f}]" for f in splited
|
|
274
|
-
|
|
275
|
-
else if @__resource
|
|
276
|
-
field = @__resource.__entityName + "[#{field}]"
|
|
277
|
-
|
|
278
|
-
result[field] = notifications
|
|
279
|
-
|
|
280
|
-
result
|
|
281
|
-
|
|
282
|
-
#
|
|
283
|
-
# Flattens complex inline structures into form notation
|
|
284
|
-
#
|
|
285
|
-
# @example Basic flattening
|
|
286
|
-
# data = foo: { bar: { baz: [] } }
|
|
287
|
-
# inner = @__foldInlineEntities(data.foo, 'foo')
|
|
288
|
-
#
|
|
289
|
-
# inner # { "foo[bar][baz]": [] }
|
|
290
|
-
#
|
|
291
|
-
# @param [Object] hash Structure to fold
|
|
292
|
-
# @param [String] scope Prefix for resulting scopes
|
|
293
|
-
# @param [Object] result Context of result for recursion
|
|
294
|
-
#
|
|
295
|
-
# @return [Hash]
|
|
296
|
-
#
|
|
297
|
-
__foldInlineEntities: (hash, scope="", result={}) ->
|
|
298
|
-
Object.each hash, (key, value) =>
|
|
299
|
-
if Object.isObject(value)
|
|
300
|
-
@__foldInlineEntities(value, "#{scope}[#{key}]", result)
|
|
301
|
-
else
|
|
302
|
-
result["#{scope}[#{key}]"] = value
|
|
303
|
-
|
|
304
|
-
result
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
#= require joosy/core/joosy
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
# Rendering and string representation helpers
|
|
5
|
-
#
|
|
6
|
-
Joosy.helpers 'Application', ->
|
|
7
|
-
|
|
8
|
-
#
|
|
9
|
-
# Converts \n into <br/> in your text
|
|
10
|
-
#
|
|
11
|
-
# @param [String] text Text to convert
|
|
12
|
-
#
|
|
13
|
-
@nl2br = (text) ->
|
|
14
|
-
text.toString().replace /\n/g, '<br/>'
|
|
15
|
-
|
|
16
|
-
#
|
|
17
|
-
# Wraps the inline block into given template
|
|
18
|
-
# Request template will receive the inline block as @yield parameter
|
|
19
|
-
#
|
|
20
|
-
# Example
|
|
21
|
-
# -# foo/baz template
|
|
22
|
-
# != @renderWrapped 'foo/bar', ->
|
|
23
|
-
# %b This string will be passed to 'foo/bar'
|
|
24
|
-
#
|
|
25
|
-
# -# foo/bar template
|
|
26
|
-
# %h1 I'm the wrapper here!
|
|
27
|
-
# != @yield
|
|
28
|
-
#
|
|
29
|
-
@renderWrapped = (template, lambda) ->
|
|
30
|
-
@render template, Joosy.Module.merge(this, yield: lambda())
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# All the tiny core stuff
|
|
3
|
-
#
|
|
4
|
-
# @module
|
|
5
|
-
#
|
|
6
|
-
@Joosy =
|
|
7
|
-
#
|
|
8
|
-
# Core modules container
|
|
9
|
-
#
|
|
10
|
-
Modules: {}
|
|
11
|
-
|
|
12
|
-
#
|
|
13
|
-
# Resources container
|
|
14
|
-
#
|
|
15
|
-
Resource: {}
|
|
16
|
-
|
|
17
|
-
#
|
|
18
|
-
# Templaters container
|
|
19
|
-
#
|
|
20
|
-
Templaters: {}
|
|
21
|
-
|
|
22
|
-
#
|
|
23
|
-
# If enabled Joosy will log to console a lot of 'in progress' stuff
|
|
24
|
-
#
|
|
25
|
-
debug: false
|
|
26
|
-
|
|
27
|
-
#
|
|
28
|
-
# Registeres anything inside specified namespace (objects chain starting from `window`)
|
|
29
|
-
#
|
|
30
|
-
# @example Basic usage
|
|
31
|
-
# Joosy.namespace 'foobar', ->
|
|
32
|
-
# class @RealThing
|
|
33
|
-
#
|
|
34
|
-
# foo = new foobar.RealThing
|
|
35
|
-
#
|
|
36
|
-
# @param [String] name Namespace keyword
|
|
37
|
-
# @param [Boolean] generator Namespace content
|
|
38
|
-
#
|
|
39
|
-
namespace: (name, generator=false) ->
|
|
40
|
-
name = name.split '.'
|
|
41
|
-
space = window
|
|
42
|
-
for part in name
|
|
43
|
-
space = space[part] ?= {}
|
|
44
|
-
|
|
45
|
-
if generator
|
|
46
|
-
generator = generator.apply space
|
|
47
|
-
for key, klass of space
|
|
48
|
-
if space.hasOwnProperty(key) &&
|
|
49
|
-
Joosy.Module.hasAncestor klass, Joosy.Module
|
|
50
|
-
klass.__namespace__ = name
|
|
51
|
-
|
|
52
|
-
#
|
|
53
|
-
# Registeres given methods as a helpers inside a given set
|
|
54
|
-
#
|
|
55
|
-
# @param [String] name Helpers set keyword
|
|
56
|
-
# @param [Boolean] generator Helpers content
|
|
57
|
-
#
|
|
58
|
-
helpers: (name, generator) ->
|
|
59
|
-
Joosy.namespace "Joosy.Helpers.#{name}", generator
|
|
60
|
-
|
|
61
|
-
#
|
|
62
|
-
# Scary `hello world`
|
|
63
|
-
#
|
|
64
|
-
test: ->
|
|
65
|
-
text = "Hi :). I'm Joosy. And everything is just fine!"
|
|
66
|
-
|
|
67
|
-
if console
|
|
68
|
-
console.log text
|
|
69
|
-
else
|
|
70
|
-
alert text
|
|
71
|
-
|
|
72
|
-
#
|
|
73
|
-
# Generates UUID
|
|
74
|
-
#
|
|
75
|
-
uuid: ->
|
|
76
|
-
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace /[xy]/g, (c) ->
|
|
77
|
-
r = Math.random() * 16 | 0
|
|
78
|
-
v = if c is 'x' then r else r & 3 | 8
|
|
79
|
-
v.toString 16
|
|
80
|
-
.toUpperCase()
|
|
81
|
-
|
|
82
|
-
#
|
|
83
|
-
# Preloads sets of images then runs callback
|
|
84
|
-
#
|
|
85
|
-
# @param [Array<String>] images Images paths
|
|
86
|
-
# @param [Function] callback Action to run when every picture was loaded (or triggered an error)
|
|
87
|
-
#
|
|
88
|
-
preloadImages: (images, callback) ->
|
|
89
|
-
unless Object.isArray(images)
|
|
90
|
-
images = [images]
|
|
91
|
-
if images.length == 0
|
|
92
|
-
callback()
|
|
93
|
-
|
|
94
|
-
ticks = images.length
|
|
95
|
-
result = []
|
|
96
|
-
checker = ->
|
|
97
|
-
if (ticks -= 1) == 0
|
|
98
|
-
callback?()
|
|
99
|
-
|
|
100
|
-
for p in images
|
|
101
|
-
result.push $('<img/>').load(checker).error(checker).attr('src', p)
|
|
102
|
-
|
|
103
|
-
result
|
|
104
|
-
|
|
105
|
-
#
|
|
106
|
-
# Basic URI builder. Joins base path with params hash
|
|
107
|
-
#
|
|
108
|
-
# @param [String] url Base url
|
|
109
|
-
# @param [Hash] params Parameters to join
|
|
110
|
-
#
|
|
111
|
-
# @example Basic usage
|
|
112
|
-
# Joosy.buildUrl 'http://joosy.ws/#!/test', {foo: 'bar'} # http://joosy.ws/?foo=bar#!/test
|
|
113
|
-
#
|
|
114
|
-
buildUrl: (url, params) ->
|
|
115
|
-
paramsString = []
|
|
116
|
-
|
|
117
|
-
Object.each params, (key, value) ->
|
|
118
|
-
paramsString.push "#{key}=#{value}"
|
|
119
|
-
|
|
120
|
-
hash = url.match(/(\#.*)?$/)[0]
|
|
121
|
-
url = url.replace /\#.*$/, ''
|
|
122
|
-
if !paramsString.isEmpty() && !url.has(/\?/)
|
|
123
|
-
url = url + "?"
|
|
124
|
-
|
|
125
|
-
paramsString = paramsString.join '&'
|
|
126
|
-
if !paramsString.isBlank() && url.last() != '?'
|
|
127
|
-
paramsString = '&' + paramsString
|
|
128
|
-
|
|
129
|
-
url + paramsString + hash
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
#= require joosy/core/joosy
|
|
2
|
-
#= require joosy/core/modules/module
|
|
3
|
-
#= require joosy/core/modules/log
|
|
4
|
-
#= require joosy/core/modules/events
|
|
5
|
-
#= require joosy/core/modules/container
|
|
6
|
-
#= require joosy/core/modules/renderer
|
|
7
|
-
#= require joosy/core/modules/time_manager
|
|
8
|
-
#= require joosy/core/modules/widgets_manager
|
|
9
|
-
#= require joosy/core/modules/filters
|
|
10
|
-
|
|
11
|
-
#
|
|
12
|
-
# Base class for all of your Joosy Layouts.
|
|
13
|
-
# @see http://guides.joosy.ws/guides/layouts-pages-and-routing.html
|
|
14
|
-
#
|
|
15
|
-
# @example Sample application layout
|
|
16
|
-
# class @ApplicationLayout extends Joosy.Layout
|
|
17
|
-
# @view 'application'
|
|
18
|
-
#
|
|
19
|
-
class Joosy.Layout extends Joosy.Module
|
|
20
|
-
@include Joosy.Modules.Log
|
|
21
|
-
@include Joosy.Modules.Events
|
|
22
|
-
@include Joosy.Modules.Container
|
|
23
|
-
@include Joosy.Modules.Renderer
|
|
24
|
-
@include Joosy.Modules.TimeManager
|
|
25
|
-
@include Joosy.Modules.WidgetsManager
|
|
26
|
-
@include Joosy.Modules.Filters
|
|
27
|
-
|
|
28
|
-
@view 'default'
|
|
29
|
-
|
|
30
|
-
#
|
|
31
|
-
# Sets the method which will controll the painting preparation proccess.
|
|
32
|
-
#
|
|
33
|
-
# This method will be called right ater previous layout {Joosy.Layout.erase} and in parallel with
|
|
34
|
-
# layout data fetching so you can use it to initiate preloader.
|
|
35
|
-
#
|
|
36
|
-
# @note Given method will be called with `complete` function as parameter. As soon as your
|
|
37
|
-
# preparations are done you should call that function.
|
|
38
|
-
#
|
|
39
|
-
# @example Sample before painter
|
|
40
|
-
# @beforePaint (complete) ->
|
|
41
|
-
# if !@data # checks if parallel fetching finished
|
|
42
|
-
# $('preloader').slideDown -> complete()
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
@beforePaint: (callback) ->
|
|
46
|
-
@::__beforePaint = callback
|
|
47
|
-
|
|
48
|
-
#
|
|
49
|
-
# Sets the method which will controll the painting proccess.
|
|
50
|
-
#
|
|
51
|
-
# This method will be called after fetching, erasing and beforePaint is complete.
|
|
52
|
-
# It should be used to setup appearance effects of layout.
|
|
53
|
-
#
|
|
54
|
-
# @note Given method will be called with `complete` function as parameter. As soon as your
|
|
55
|
-
# preparations are done you should call that function.
|
|
56
|
-
#
|
|
57
|
-
# @example Sample painter
|
|
58
|
-
# @paint (complete) ->
|
|
59
|
-
# @container.fadeIn -> complete()
|
|
60
|
-
#
|
|
61
|
-
@paint: (callback) ->
|
|
62
|
-
@::__paint = callback
|
|
63
|
-
|
|
64
|
-
#
|
|
65
|
-
# Sets the method which will controll the erasing proccess.
|
|
66
|
-
#
|
|
67
|
-
# Use this method to setup hiding effect.
|
|
68
|
-
#
|
|
69
|
-
# @note Given method will be called with `complete` function as parameter. As soon as your
|
|
70
|
-
# preparations are done you should call that function.
|
|
71
|
-
#
|
|
72
|
-
# @note This method will be caled _before_ unload routines so in theory you can
|
|
73
|
-
# access layout data from that. Think twice if you are doing it right though.
|
|
74
|
-
#
|
|
75
|
-
# @example Sample eraser
|
|
76
|
-
# @erase (complete) ->
|
|
77
|
-
# @container.fadeOut -> complete()
|
|
78
|
-
#
|
|
79
|
-
@erase: (callback) ->
|
|
80
|
-
@::__erase = callback
|
|
81
|
-
|
|
82
|
-
#
|
|
83
|
-
# Sets the method which will controll the data fetching proccess.
|
|
84
|
-
#
|
|
85
|
-
# @note Given method will be called with `complete` function as parameter. As soon as your
|
|
86
|
-
# preparations are done you should call that function.
|
|
87
|
-
#
|
|
88
|
-
# @note You are strongly encouraged to NOT fetch anything with Layout!
|
|
89
|
-
# Use {Joosy.Page.fetch}
|
|
90
|
-
#
|
|
91
|
-
# @example Basic usage
|
|
92
|
-
# @fetch (complete) ->
|
|
93
|
-
# $.get '/rumbas', (@data) => complete()
|
|
94
|
-
#
|
|
95
|
-
@fetch: (callback) ->
|
|
96
|
-
@::__fetch = callback
|
|
97
|
-
|
|
98
|
-
#
|
|
99
|
-
# Defaults to `false` to ease beforePaint state check.
|
|
100
|
-
#
|
|
101
|
-
data: false
|
|
102
|
-
|
|
103
|
-
#
|
|
104
|
-
# @param [Hash] params List of route params
|
|
105
|
-
#
|
|
106
|
-
constructor: (@params) ->
|
|
107
|
-
|
|
108
|
-
#
|
|
109
|
-
# @see Joosy.Router#navigate
|
|
110
|
-
#
|
|
111
|
-
navigate: (args...) ->
|
|
112
|
-
Joosy.Router.navigate(args...)
|
|
113
|
-
|
|
114
|
-
#
|
|
115
|
-
# This is required by {Joosy.Modules.Renderer}
|
|
116
|
-
# Sets the base template dir to app_name/templates/layouts
|
|
117
|
-
#
|
|
118
|
-
__renderSection: ->
|
|
119
|
-
'layouts'
|
|
120
|
-
|
|
121
|
-
#
|
|
122
|
-
# Layout bootstrap proccess.
|
|
123
|
-
#
|
|
124
|
-
# * {Joosy.Modules.Container#refreshElements}
|
|
125
|
-
# * {Joosy.Modules.Container#__delegateEvents}
|
|
126
|
-
# * {Joosy.Modules.WidgetsManager#__setupWidgets}
|
|
127
|
-
# * {Joosy.Modules.Filters#__runAfterLoads}
|
|
128
|
-
#
|
|
129
|
-
__load: (@container) ->
|
|
130
|
-
@refreshElements()
|
|
131
|
-
@__delegateEvents()
|
|
132
|
-
@__setupWidgets()
|
|
133
|
-
@__runAfterLoads()
|
|
134
|
-
|
|
135
|
-
#
|
|
136
|
-
# Layout destruction proccess.
|
|
137
|
-
#
|
|
138
|
-
# * {Joosy.Modules.TimeManager#__clearTime}
|
|
139
|
-
# * {Joosy.Modules.WidgetsManager#__unloadWidgets}
|
|
140
|
-
# * {Joosy.Modules.Renderer#__removeMetamorphs}
|
|
141
|
-
# * {Joosy.Modules.Filters#__runAfterUnloads}
|
|
142
|
-
#
|
|
143
|
-
__unload: ->
|
|
144
|
-
@__clearTime()
|
|
145
|
-
@__unloadWidgets()
|
|
146
|
-
@__removeMetamorphs()
|
|
147
|
-
@__runAfterUnloads()
|
|
148
|
-
|
|
149
|
-
#
|
|
150
|
-
# @todo Rename this shit already. We are not going to release having function that marks
|
|
151
|
-
# element with UUID called `yield`.
|
|
152
|
-
#
|
|
153
|
-
yield: ->
|
|
154
|
-
@uuid = Joosy.uuid()
|
|
155
|
-
|
|
156
|
-
#
|
|
157
|
-
# Gets layout element.
|
|
158
|
-
#
|
|
159
|
-
# @return [jQuery]
|
|
160
|
-
#
|
|
161
|
-
content: ->
|
|
162
|
-
$("##{@uuid}")
|