ultimate-base 0.2.4 → 0.3.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 +4 -1
- data/.rvmrc +0 -1
- data/.rvmrc.example +0 -1
- data/Gemfile +6 -0
- data/Gemfile.lock +113 -1
- data/app/assets/javascripts/ultimate/backbone/base.js.coffee +14 -2
- data/app/assets/javascripts/ultimate/backbone/extra/jquery-plugin-adapter.js.coffee +1 -1
- data/app/assets/javascripts/ultimate/backbone/model.js.coffee +6 -0
- data/app/assets/javascripts/ultimate/backbone/view.js.coffee +5 -4
- data/app/assets/javascripts/ultimate/backbone/views/slider.js.coffee +4 -1
- data/app/assets/javascripts/ultimate/helpers/asset_tag.js.coffee +71 -54
- data/app/assets/javascripts/ultimate/helpers/base.js.coffee +3 -0
- data/app/assets/javascripts/ultimate/helpers/decor.js.coffee +19 -14
- data/app/assets/javascripts/ultimate/helpers/number.js.coffee +600 -0
- data/app/assets/javascripts/ultimate/helpers/record_tag.js.coffee +66 -0
- data/app/assets/javascripts/ultimate/helpers/tag.js.coffee +77 -0
- data/app/assets/javascripts/ultimate/helpers/url.js.coffee +49 -0
- data/app/assets/javascripts/ultimate/helpers.js.coffee +39 -66
- data/app/assets/javascripts/ultimate/{devise.js.coffee → improves/devise.js.coffee} +0 -0
- data/app/assets/javascripts/ultimate/improves/i18n-lite.js.coffee +18 -12
- data/app/assets/javascripts/ultimate/improves/magic-radios.js.coffee +2 -0
- data/app/assets/javascripts/ultimate/improves/typed-fields.js.coffee +13 -14
- data/app/assets/javascripts/ultimate/{base.js.coffee → jquery.base.js.coffee} +24 -37
- data/app/assets/javascripts/ultimate/{experimental/_inflections → underscore}/underscore.inflection.js +19 -18
- data/app/assets/javascripts/ultimate/underscore/underscore.outcasts.js.coffee +123 -0
- data/app/assets/javascripts/ultimate/underscore/underscore.string.js +16 -6
- data/config/routes.rb +2 -0
- data/lib/{ultimate-base → ultimate/base}/engine.rb +1 -0
- data/lib/{ultimate-base → ultimate/base}/version.rb +1 -1
- data/lib/ultimate/base.rb +10 -0
- data/lib/{ultimate-base → ultimate}/extensions/directive_processor.rb +0 -0
- data/lib/{ultimate-base → ultimate}/extensions/sass_script_functions.rb +0 -0
- data/scripts/rails +8 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/_emfile +18 -0
- data/{app/assets/javascripts/ultimate/helpers/forms.js.coffee → test/dummy/app/assets/images/.gitkeep} +0 -0
- data/test/dummy/app/assets/javascripts/application.js +3 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/global/forms.css.scss +65 -0
- data/test/dummy/app/assets/stylesheets/global/layout/footer.scss +18 -0
- data/test/dummy/app/assets/stylesheets/global/layout/header.scss +13 -0
- data/test/dummy/app/assets/stylesheets/global/layout/main-menu.scss +68 -0
- data/test/dummy/app/assets/stylesheets/global/layout.css.scss +46 -0
- data/test/dummy/app/assets/stylesheets/global/reserved.css.scss +79 -0
- data/test/dummy/app/assets/stylesheets/global/reset.css.scss +85 -0
- data/test/dummy/app/assets/stylesheets/global/structures.css.scss +9 -0
- data/test/dummy/app/assets/stylesheets/import/base.scss +34 -0
- data/test/dummy/app/assets/stylesheets/plugins/qunit.css.scss +3 -0
- data/test/dummy/app/controllers/application_controller.rb +4 -0
- data/test/dummy/app/controllers/main_controller.rb +8 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/application/_footer.html.haml +3 -0
- data/test/dummy/app/views/application/_header.html.haml +4 -0
- data/test/dummy/app/views/application/_main_menu.html.haml +11 -0
- data/test/dummy/app/views/layouts/application.html.haml +24 -0
- data/test/dummy/app/views/main/index.html.haml +13 -0
- data/test/dummy/app/views/main/qunit.html.haml +7 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +40 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/qunit-rails.rb +1 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +63 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/javascripts/all_tests.js.coffee +13 -0
- data/test/javascripts/test_helper.js.coffee +3 -0
- data/test/javascripts/tests/base_test.js.coffee +42 -0
- data/test/javascripts/tests/helpers/asset_tag_test.js.coffee +51 -0
- data/test/javascripts/tests/helpers/number_test.js.coffee +250 -0
- data/test/javascripts/tests/helpers/record_tag_test.js.coffee +56 -0
- data/test/javascripts/tests/helpers/tag_test.js.coffee +33 -0
- data/test/javascripts/tests/helpers/url_test.js.coffee +28 -0
- data/test/javascripts/tests/helpers_test.js.coffee +47 -0
- data/test/javascripts/tests/improves/i18n-lite_test.js.coffee +25 -0
- data/test/javascripts/tests/underscore/underscore.outcasts.test.js.coffee +38 -0
- data/test/stylesheets/test_helper.css +4 -0
- data/ultimate-base.gemspec +4 -4
- metadata +116 -24
- data/app/assets/javascripts/ultimate/bus.js.coffee +0 -57
- data/app/assets/javascripts/ultimate/experimental/_inflections/dzone.inflections.js +0 -154
- data/app/assets/javascripts/ultimate/helpers/array.js.coffee +0 -63
- data/app/assets/javascripts/ultimate/helpers/tags.js.coffee +0 -73
- data/app/assets/javascripts/ultimate/widgets/dock.js.coffee +0 -70
- data/app/assets/javascripts/ultimate/widgets/gear.js.coffee +0 -84
- data/app/assets/javascripts/ultimate/widgets/jquery-ext.js.coffee +0 -104
- data/app/assets/javascripts/ultimate/widgets/jquery.adapter.js.coffee +0 -62
- data/app/assets/javascripts/ultimate/widgets/widget.js.coffee +0 -115
- data/lib/ultimate-base.rb +0 -10
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# Ultimate base object
|
|
2
|
-
# * base OOP improves
|
|
3
|
-
# * instances controls
|
|
4
|
-
# * options and settings controls
|
|
5
|
-
# * translations
|
|
6
|
-
|
|
7
|
-
console.log 'Ultimate.Proto.Gear', Ultimate if console?
|
|
8
|
-
|
|
9
|
-
class Ultimate.Proto.Gear
|
|
10
|
-
|
|
11
|
-
@className: 'Gear'
|
|
12
|
-
|
|
13
|
-
# commented because must be uniq for independent widgets
|
|
14
|
-
#@instances: []
|
|
15
|
-
@maxInstances: Infinity # 0 for intrfaces, 1 for singleton
|
|
16
|
-
|
|
17
|
-
@canCreateInstance = ->
|
|
18
|
-
cout 'info', 'Gear.canCreateInstance', @name, @instances, @maxInstances
|
|
19
|
-
(@instances or []).length < @maxInstances
|
|
20
|
-
|
|
21
|
-
@pushInstance = (instance) ->
|
|
22
|
-
@instances ||= []
|
|
23
|
-
@instances.push instance
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@defaults:
|
|
28
|
-
constants: {}
|
|
29
|
-
locales:
|
|
30
|
-
'en':
|
|
31
|
-
description: 'Base Ultimate js Class'
|
|
32
|
-
'ru':
|
|
33
|
-
description: 'Базовай Ultimate js-класс'
|
|
34
|
-
options:
|
|
35
|
-
locale: 'en'
|
|
36
|
-
translations: {}
|
|
37
|
-
|
|
38
|
-
settings: {}
|
|
39
|
-
|
|
40
|
-
uniqId: null
|
|
41
|
-
|
|
42
|
-
debugMode: false
|
|
43
|
-
|
|
44
|
-
constructor: (options = {}) ->
|
|
45
|
-
@uniqId = _.uniqueId @constructor.className
|
|
46
|
-
@constructor.pushInstance @
|
|
47
|
-
@updateSettings @constructor.defaults.options
|
|
48
|
-
@updateSettings @initTranslations(options)
|
|
49
|
-
@debug "#{@constructor.className}.constructor()", @uniqId, options
|
|
50
|
-
|
|
51
|
-
# use I18n, and modify locale and translations in options
|
|
52
|
-
# modify and return merged data
|
|
53
|
-
initTranslations: (options) ->
|
|
54
|
-
# if global compatible I18n
|
|
55
|
-
if I18n? and I18n.locale and I18n.t
|
|
56
|
-
options['locale'] ?= I18n.locale
|
|
57
|
-
if options['locale'] is I18n.locale
|
|
58
|
-
# pointing to defaults locales of language specified in I18n
|
|
59
|
-
_defaultLocales = @constructor.defaults.locales[I18n.locale]
|
|
60
|
-
unless _defaultLocales['loaded']
|
|
61
|
-
_defaultLocales['loaded'] = true
|
|
62
|
-
# try read localized strings
|
|
63
|
-
if _localesFromI18n = I18n.t options['i18nKey'] or _.underscored(@constructor.className)
|
|
64
|
-
# fill it from I18n
|
|
65
|
-
_defaultLocales[_.camelize key] = value for key, value of _localesFromI18n
|
|
66
|
-
options
|
|
67
|
-
|
|
68
|
-
getSettings: ->
|
|
69
|
-
@settings
|
|
70
|
-
|
|
71
|
-
setSettings: (settings) ->
|
|
72
|
-
@settings = settings
|
|
73
|
-
|
|
74
|
-
updateSettings: (options) ->
|
|
75
|
-
cout 'updateSettings', options
|
|
76
|
-
for optionsKey, optionsValue of options when optionsKey in @ then @[optionsKey] = optionsValue
|
|
77
|
-
translations = if (l = options['locale']) then @constructor.defaults.locales[l] or {} else {}
|
|
78
|
-
$.extend true, @settings, translations: translations, options
|
|
79
|
-
|
|
80
|
-
debug: ->
|
|
81
|
-
if @settings.debugMode
|
|
82
|
-
a = ["DEBUG | #{@constructor.className} >>> "]
|
|
83
|
-
Array::push.apply a, arguments
|
|
84
|
-
cout.apply @, a
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
###
|
|
2
|
-
For begin Ultimate actions use:
|
|
3
|
-
$ ->
|
|
4
|
-
Ultimate.initialize()
|
|
5
|
-
cout '>>> go $(\'body\').bindWidgets Ultimate.Widgets'
|
|
6
|
-
cout '>>> binded', $('body').bindWidgets Ultimate.Widgets
|
|
7
|
-
###
|
|
8
|
-
|
|
9
|
-
do ($ = jQuery) ->
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# TODO arguments
|
|
13
|
-
$.fn.getWidgets = (widgetClass = null, inheritance = false, domDeep = false) ->
|
|
14
|
-
if not @length
|
|
15
|
-
return []
|
|
16
|
-
else if @length is 1
|
|
17
|
-
widgets = @data('widgets') or []
|
|
18
|
-
else
|
|
19
|
-
# TODO check work and perf tests
|
|
20
|
-
widgets = _.flatten($(o).data('widgets') or [] for o in @, true)
|
|
21
|
-
#2: @map -> $(@).data('widgets') or []
|
|
22
|
-
#3: _.flatten ( @map -> $(@).data('widgets') or [] ), true
|
|
23
|
-
if widgetClass?
|
|
24
|
-
_.filter widgets, if inheritance then (w) -> w instanceof widgetClass else (w) -> w.costructor is widgetClass
|
|
25
|
-
else
|
|
26
|
-
widgets
|
|
27
|
-
|
|
28
|
-
$.fn.getWidget = (widgetClass, inheritance = false) ->
|
|
29
|
-
if _.isString widgetClass
|
|
30
|
-
for o in @
|
|
31
|
-
widgets = $(o).data('widgets') or []
|
|
32
|
-
for w in widgets
|
|
33
|
-
return w if w.constructor.className is widgetClass
|
|
34
|
-
else if Ultimate.isWidgetClass widgetClass
|
|
35
|
-
for o in @
|
|
36
|
-
widgets = $(o).data('widgets') or []
|
|
37
|
-
if inheritance
|
|
38
|
-
for w in widgets
|
|
39
|
-
return w if w instanceof widgetClass
|
|
40
|
-
else
|
|
41
|
-
for w in widgets
|
|
42
|
-
return w if w.constructor is widgetClass
|
|
43
|
-
false
|
|
44
|
-
|
|
45
|
-
$.fn.hasWidget = (widgetClass) ->
|
|
46
|
-
if _.isString widgetClass
|
|
47
|
-
for o in @
|
|
48
|
-
return true if _.any $(o).data('widgets') or [], (w) -> w.constructor.className is widgetClass
|
|
49
|
-
else if Ultimate.isWidgetClass widgetClass
|
|
50
|
-
for o in @
|
|
51
|
-
return true if _.any $(o).data('widgets') or [], (w) -> w.constructor is widgetClass
|
|
52
|
-
false
|
|
53
|
-
|
|
54
|
-
$.fn.bindOneWidget = (widgetClass, options = {}) ->
|
|
55
|
-
Ultimate.gcWidgets()
|
|
56
|
-
bindedWidget = null
|
|
57
|
-
if widgetClass.canCreateInstance()
|
|
58
|
-
if @length
|
|
59
|
-
selector = "#{widgetClass.selector}:not(.prevent-binding)"
|
|
60
|
-
jContainer = if @is(selector) then @filter(selector) else @find(selector)
|
|
61
|
-
if (l = jContainer.length)
|
|
62
|
-
if l is 1
|
|
63
|
-
bindedWidget = Ultimate.createWidget widgetClass, jContainer, options
|
|
64
|
-
else
|
|
65
|
-
warning "$.fn.bindOneWidget() found #{l} elements by #{selector}, when need only 1"
|
|
66
|
-
else
|
|
67
|
-
warning "$.fn.bindOneWidget() not found elements by #{selector}"
|
|
68
|
-
else
|
|
69
|
-
warning "$.fn.bindOneWidget() call from empty jQuery()"
|
|
70
|
-
else
|
|
71
|
-
warning "Widget #{widgetClass.className} can't create call from empty jQuery()"
|
|
72
|
-
bindedWidget
|
|
73
|
-
|
|
74
|
-
$.fn.bindWidget = (widgetClass, options = {}) ->
|
|
75
|
-
Ultimate.gcWidgets()
|
|
76
|
-
bindedWidgets = []
|
|
77
|
-
if @length
|
|
78
|
-
( if @is(widgetClass.selector) then @ else @find(widgetClass.selector) ).filter(':not(.prevent-binding)').each ->
|
|
79
|
-
if widgetClass.canCreateInstance()
|
|
80
|
-
jContainer = $ @
|
|
81
|
-
if widget = Ultimate.createWidget widgetClass, jContainer, options
|
|
82
|
-
bindedWidgets.push widget
|
|
83
|
-
else
|
|
84
|
-
false
|
|
85
|
-
bindedWidgets
|
|
86
|
-
|
|
87
|
-
$.fn.bindWidgets = (widgetClasses = Ultimate.LazyWidgets, options = {}) ->
|
|
88
|
-
cout 'info', 'bindWidgets begin'
|
|
89
|
-
bindedWidgets = []
|
|
90
|
-
if @length
|
|
91
|
-
bindedWidgets = for widgetName, widgetClass of widgetClasses when widgetClass.canCreateInstance()
|
|
92
|
-
widgetClass.constructor.className ||= widgetName
|
|
93
|
-
@bindWidget widgetClass, options
|
|
94
|
-
_.flatten bindedWidgets, true
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
# TODO filtering by widgetClass
|
|
99
|
-
# TODO enother algorithm with enother projection
|
|
100
|
-
$.fn.closestWidgets = (widgetClass = null) ->
|
|
101
|
-
widgets = []
|
|
102
|
-
jTry = @
|
|
103
|
-
jTry = jTry.parent() while jTry.length and not (widgets = jTry.getWidgets()).length
|
|
104
|
-
widgets
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# jQueryPluginAdapter
|
|
2
|
-
|
|
3
|
-
do ($ = jQuery) ->
|
|
4
|
-
$.fn.pluginAdapter = (widgetClass, pluginName, pluginArgs) ->
|
|
5
|
-
a = args pluginArgs
|
|
6
|
-
argsLength = a.length
|
|
7
|
-
# Shall return the Widget, if have arguments and last argument of the call is a Boolean true.
|
|
8
|
-
_returnWidget =
|
|
9
|
-
if argsLength and _.isBoolean a[argsLength - 1]
|
|
10
|
-
argsLength--
|
|
11
|
-
a.pop()
|
|
12
|
-
else
|
|
13
|
-
false
|
|
14
|
-
unless @length
|
|
15
|
-
return if _returnWidget then undefined else @
|
|
16
|
-
# get the first TODO analize, maybe each?
|
|
17
|
-
jContainer = @first()
|
|
18
|
-
# try to get the Widget-object, controlling everything that happens in our magical container
|
|
19
|
-
widget = jContainer.getWidget(widgetClass)
|
|
20
|
-
if widget and widget.jContainer[0] is jContainer[0]
|
|
21
|
-
command = null
|
|
22
|
-
if argsLength and _.isString a[0]
|
|
23
|
-
command = a.shift()
|
|
24
|
-
else
|
|
25
|
-
return widget if _returnWidget
|
|
26
|
-
return jContainer unless argsLength
|
|
27
|
-
command = 'updateSettings'
|
|
28
|
-
if _.isFunction widget[command]
|
|
29
|
-
return widget[command].apply widget, a
|
|
30
|
-
else
|
|
31
|
-
$.error "Command [#{command}] does not exist on jQuery.#{pluginName}()"
|
|
32
|
-
else
|
|
33
|
-
options = if argsLength then a[0] else {}
|
|
34
|
-
if $.isPlainObject options
|
|
35
|
-
widget = Ultimate.createWidget widgetClass, jContainer, options
|
|
36
|
-
else
|
|
37
|
-
$.error "First argument of jQuery.#{pluginName}() must be plain object"
|
|
38
|
-
if _returnWidget then widget else jContainer
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# TODO rewrite docs
|
|
42
|
-
###
|
|
43
|
-
* Invoke Ultimate Flash functionality for the first element in the set of matched elements.
|
|
44
|
-
* If last argument {Boolean} true, then returns {Widget}.
|
|
45
|
-
* @usage
|
|
46
|
-
*** standart actions ***
|
|
47
|
-
* construction .ultimateFlash([Object options = {}]) ~ {jQuery} jContainer
|
|
48
|
-
* show .ultimateFlash('show', String type, String text) ~ {jQuery} jFlash | {Boolean} false
|
|
49
|
-
* notice .ultimateFlash('notice', String text) ~ {jQuery} jFlash | {Boolean} false
|
|
50
|
-
* alert .ultimateFlash('alert', String text) ~ {jQuery} jFlash | {Boolean} false
|
|
51
|
-
*** extended actions ***
|
|
52
|
-
* getSettings .ultimateFlash('getSettings') ~ {Object} settings
|
|
53
|
-
* setSettings .ultimateFlash('setSettings', {Object} settings) ~ {jQuery} jContainer
|
|
54
|
-
* updateSettings .ultimateFlash({Object} options) ~ {Object} settings
|
|
55
|
-
* auto .ultimateFlash('auto', {ArrayOrObject} obj) ~ {Array} ajFlashes | {Boolean} false
|
|
56
|
-
* ajaxSuccess .ultimateFlash('ajaxSuccess'[, Arguments successArgs = []])
|
|
57
|
-
* ajaxError .ultimateFlash('ajaxError'[, String text = settings.translations.defaultErrorText][, Arguments errorArgs = []])
|
|
58
|
-
###
|
|
59
|
-
|
|
60
|
-
Ultimate.createPlugin = (widgetClass, pluginName = widgetClass.className) ->
|
|
61
|
-
cout "Ultimate.createPlugin", pluginName
|
|
62
|
-
jQuery.fn[pluginName] = -> @pluginAdapter widgetClass, pluginName, arguments
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
# require:
|
|
2
|
-
# jquery ~> 1.7.0
|
|
3
|
-
# underscore ~> 1.3.0
|
|
4
|
-
|
|
5
|
-
# TODO inheritance:
|
|
6
|
-
# ? class Classes.Proto.Observer see jU-widget
|
|
7
|
-
|
|
8
|
-
console.log 'Ultimate.Proto.Widget', Ultimate if console?
|
|
9
|
-
|
|
10
|
-
class Ultimate.Proto.Widget extends Ultimate.Proto.Gear
|
|
11
|
-
|
|
12
|
-
@className: 'Widget' # set during bindWidgets()
|
|
13
|
-
|
|
14
|
-
@defaults:
|
|
15
|
-
locales:
|
|
16
|
-
'en':
|
|
17
|
-
description: 'Proto Widget'
|
|
18
|
-
'ru':
|
|
19
|
-
description: 'Прото Виджет'
|
|
20
|
-
|
|
21
|
-
# TODO move to @defaults.options :
|
|
22
|
-
@loadingWidthMethodName: 'innerWidth'
|
|
23
|
-
@loadingHeightMethodName: 'innerHeight'
|
|
24
|
-
loadingState: false
|
|
25
|
-
|
|
26
|
-
eventsMatcher = /^(\S+)\s*(.*)$/ # /^\s*([\w\.:]+)(\s+(.+?))?\s*$/
|
|
27
|
-
@events: {}
|
|
28
|
-
eventsNamespace: null
|
|
29
|
-
|
|
30
|
-
@nodes:
|
|
31
|
-
jNoInfo: '.no-info'
|
|
32
|
-
|
|
33
|
-
jContainer: null
|
|
34
|
-
|
|
35
|
-
constructor: (@jContainer, options = {}) ->
|
|
36
|
-
data = @jContainer.data()
|
|
37
|
-
if data
|
|
38
|
-
widgets = _delete data, 'widgets'
|
|
39
|
-
options = $.extend true, {}, data, options
|
|
40
|
-
super options
|
|
41
|
-
if widgets
|
|
42
|
-
widgets.push @
|
|
43
|
-
else
|
|
44
|
-
@jContainer.data 'widgets', [@]
|
|
45
|
-
@eventsNamespace = ".widget-#{@uniqId}"
|
|
46
|
-
@bindEvents()
|
|
47
|
-
@findNodes()
|
|
48
|
-
|
|
49
|
-
isGarbage: -> not (@jContainer and @jContainer.parent().length)
|
|
50
|
-
|
|
51
|
-
unbindEvents: ->
|
|
52
|
-
@jContainer.off @eventsNamespace
|
|
53
|
-
|
|
54
|
-
bindEvents: (events = @constructor.events) ->
|
|
55
|
-
# TODO check IE key with unwordchars ('ajax:error'), and Array.forEach() functionality
|
|
56
|
-
@unbindEvents()
|
|
57
|
-
_.each events, (method, eventRoute) =>
|
|
58
|
-
if _.isString method
|
|
59
|
-
if _.isFunction @[method]
|
|
60
|
-
method = @[method]
|
|
61
|
-
else
|
|
62
|
-
$.error "Method \"#{method}\" does not exist in #{@constructor.className}.bindEvents()"
|
|
63
|
-
if _.isFunction method
|
|
64
|
-
matchedEventRoute = eventRoute.match eventsMatcher
|
|
65
|
-
if matchedEventRoute
|
|
66
|
-
matchedEventRoute.shift()
|
|
67
|
-
[eventName, selector] = matchedEventRoute
|
|
68
|
-
eventName = "#{eventName}#{@eventsNamespace}"
|
|
69
|
-
method = _.bind method, @
|
|
70
|
-
if selector
|
|
71
|
-
@jContainer.on eventName, selector, method
|
|
72
|
-
else
|
|
73
|
-
@jContainer.on eventName, method
|
|
74
|
-
# http://37signals.com/svn/posts/3137-using-event-capturing-to-improve-basecamp-page-load-times
|
|
75
|
-
else
|
|
76
|
-
$.error "Bad event route \"#{eventRoute}\" in #{@constructor.className}.bindEvents()"
|
|
77
|
-
else
|
|
78
|
-
$.error "No method for route \"#{eventRoute}\" in #{@constructor.className}.bindEvents()"
|
|
79
|
-
|
|
80
|
-
findNodes: (jRoot = @jContainer, nodes = @constructor.nodes) ->
|
|
81
|
-
jNodes = {}
|
|
82
|
-
for nodeName, selector of nodes
|
|
83
|
-
_isObject = _.isObject selector
|
|
84
|
-
if _isObject
|
|
85
|
-
nestedNodes = selector
|
|
86
|
-
selector = _delete nestedNodes, 'selector'
|
|
87
|
-
jNodes[nodeName] = @[nodeName] = jRoot.find(selector)
|
|
88
|
-
if _isObject
|
|
89
|
-
_.extend jNodes, @findNodes(jNodes[nodeName], nestedNodes)
|
|
90
|
-
jNodes
|
|
91
|
-
|
|
92
|
-
replaceContainer: (jNewContainer, sideCall = false) ->
|
|
93
|
-
unless sideCall
|
|
94
|
-
widgets = @jContainer.data 'widgets'
|
|
95
|
-
jNewContainer.data 'widgets', widgets
|
|
96
|
-
@jContainer.replaceWith jNewContainer
|
|
97
|
-
for widget in widgets when widget isnt @
|
|
98
|
-
widget.replaceContainer jNewContainer, true
|
|
99
|
-
@jContainer = jNewContainer
|
|
100
|
-
@unbindEvents()
|
|
101
|
-
@bindEvents()
|
|
102
|
-
|
|
103
|
-
# overloadable
|
|
104
|
-
getJLoadingContainer: -> @jContainer
|
|
105
|
-
|
|
106
|
-
loading: (state, text = '') ->
|
|
107
|
-
jLoadingContainer = @getJLoadingContainer()
|
|
108
|
-
if jLoadingContainer and jLoadingContainer.length
|
|
109
|
-
jLoadingContainer.children('.loading-overlay').remove()
|
|
110
|
-
if @loadingState = state
|
|
111
|
-
width = jLoadingContainer[@constructor.loadingWidthMethodName]()
|
|
112
|
-
height = jLoadingContainer[@constructor.loadingHeightMethodName]()
|
|
113
|
-
text = "<span class=\"text\">#{text}</span>" if text
|
|
114
|
-
style = "width: #{width}px; height: #{height}px; line-height: #{height}px;"
|
|
115
|
-
jLoadingContainer.append "<div class=\"loading-overlay\" style=\"#{style}\"><span class=\"circle\"></span>#{text}</div>"
|
data/lib/ultimate-base.rb
DELETED