ultimate-base 0.2.4 → 0.3.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,77 @@
|
|
1
|
+
#= require ./base
|
2
|
+
|
3
|
+
@Ultimate.Helpers.Tag =
|
4
|
+
|
5
|
+
BOOLEAN_ATTRIBUTES: "disabled readonly multiple checked autobuffer
|
6
|
+
autoplay controls loop selected hidden scoped async
|
7
|
+
defer reversed ismap seemless muted required
|
8
|
+
autofocus novalidate formnovalidate open pubdate itemscope".split(/\s+/)
|
9
|
+
|
10
|
+
PRE_CONTENT_STRINGS:
|
11
|
+
textarea: "\n"
|
12
|
+
|
13
|
+
tag: (tag_name, options = {}, open = false, escape = true) ->
|
14
|
+
"<#{tag_name}#{@tag_options(options)}#{if open then '>' else ' />'}"
|
15
|
+
|
16
|
+
content_tag: (name, content_or_options_with_block = null, options = null, escape = true, block = null) ->
|
17
|
+
if block = _.outcasts.blockGiven(arguments)
|
18
|
+
options = content_or_options_with_block
|
19
|
+
@content_tag_string(name, block(), options, escape)
|
20
|
+
else
|
21
|
+
@content_tag_string(name, content_or_options_with_block, options, escape)
|
22
|
+
|
23
|
+
content_tag_string: (name, content = '', options = {}, escape = true) ->
|
24
|
+
content = _.escape(content) if escape
|
25
|
+
"<#{name}#{@tag_options(options, escape)}>#{@PRE_CONTENT_STRINGS[name] ? ''}#{content}</#{name}>"
|
26
|
+
|
27
|
+
html_options_to_s: (html_options, escape = false, prefix = "") ->
|
28
|
+
deprecate 'html_options_to_s()', "tag_options()"
|
29
|
+
@tag_options.apply(@, arguments)
|
30
|
+
|
31
|
+
tag_options: (options, escape = true) ->
|
32
|
+
return "" if _.isEmpty(options)
|
33
|
+
attrs = []
|
34
|
+
for key, value of options
|
35
|
+
if key is "data" and _.isObject(value)
|
36
|
+
for k, v of value
|
37
|
+
attrs.push @data_tag_option(k, v, escape)
|
38
|
+
else if _.include(@BOOLEAN_ATTRIBUTES, key)
|
39
|
+
attrs.push @boolean_tag_option(key) if value
|
40
|
+
else if value?
|
41
|
+
attrs.push @tag_option(key, value, escape)
|
42
|
+
if _.isEmpty(attrs) then "" else " #{attrs.sort().join(' ')}"
|
43
|
+
|
44
|
+
data_tag_option: (key, value, escape) ->
|
45
|
+
key = "data-#{_.string.dasherize(key)}"
|
46
|
+
value = JSON.stringify(value) if JSON? and _.isObject(value)
|
47
|
+
@tag_option(key, value, escape)
|
48
|
+
|
49
|
+
boolean_tag_option: (key) ->
|
50
|
+
"#{key}=\"#{key}\""
|
51
|
+
|
52
|
+
tag_option: (key, value, escape) ->
|
53
|
+
value = value.join(" ") if _.isArray(value)
|
54
|
+
value = _.string.escapeHTML(value) if escape
|
55
|
+
"#{key}=\"#{value}\""
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
# # TODO more zen features: +, *x, {content}
|
60
|
+
# # TODO cache
|
61
|
+
# selectorToHtml: (selector) ->
|
62
|
+
# if matches = selector.match(/^[\s>]*([\w\.]+)(.*)$/)
|
63
|
+
# selector = matches[1]
|
64
|
+
# continuation = matches[2]#{(if open then ">" else " />")}
|
65
|
+
# classes = selector.split(".")
|
66
|
+
# tag_name = classes.shift() or "div"
|
67
|
+
# html_options = {}
|
68
|
+
# html_options["class"] = classes.join(" ") if classes.length
|
69
|
+
# if continuation
|
70
|
+
# @content_tag(tag_name, @selectorToHtml(continuation), html_options)
|
71
|
+
# else
|
72
|
+
# @tag(tag_name, html_options)
|
73
|
+
# else
|
74
|
+
# ""
|
75
|
+
#
|
76
|
+
concat_class: ->
|
77
|
+
_.uniq(_.compact(arguments).join(' ').split(/\s+/)).join(' ')
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#= require ./base
|
2
|
+
#= require ./tag
|
3
|
+
|
4
|
+
@Ultimate.Helpers.Url =
|
5
|
+
|
6
|
+
url_for: (options = null) ->
|
7
|
+
if _.isString(options)
|
8
|
+
if options is "back"
|
9
|
+
'javascript:history.back();'
|
10
|
+
else
|
11
|
+
options
|
12
|
+
else unless _.isEmpty(options)
|
13
|
+
url = _.result(options, 'url') ? ''
|
14
|
+
if _.isObject(options)
|
15
|
+
options = _.clone(options)
|
16
|
+
delete options['url']
|
17
|
+
anchor = _.outcasts.delete(options, 'anchor')
|
18
|
+
url += "?#{_.map(options, (value, key) -> "#{key}=#{value}").sort().join('&')}" unless _.isEmpty(options)
|
19
|
+
url += "##{anchor}" if anchor
|
20
|
+
url
|
21
|
+
else
|
22
|
+
'javascript:;'
|
23
|
+
|
24
|
+
link_to: (name = null, options = null, html_options = null, block = null) ->
|
25
|
+
[html_options, options] = [options, name] if block = _.outcasts.blockGiven(arguments)
|
26
|
+
options ||= {}
|
27
|
+
url = @url_for(options)
|
28
|
+
html_options = @_convert_options_to_data_attributes(options, html_options)
|
29
|
+
html_options["href"] ||= url
|
30
|
+
Ultimate.Helpers.Tag.content_tag("a", name or url, html_options, false, block)
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
_convert_options_to_data_attributes: (options, html_options) ->
|
35
|
+
if html_options
|
36
|
+
html_options['data-remote'] = 'true' if @_link_to_remote_options(options) or @_link_to_remote_options(html_options)
|
37
|
+
method = _.outcasts.delete(html_options, 'method')
|
38
|
+
@_add_method_to_attributes(html_options, method) if method
|
39
|
+
html_options
|
40
|
+
else
|
41
|
+
if @_link_to_remote_options(options) then {'data-remote': 'true'} else {}
|
42
|
+
|
43
|
+
_link_to_remote_options: (options) ->
|
44
|
+
_.isObject(options) and _.outcasts.delete(options, 'remote')
|
45
|
+
|
46
|
+
_add_method_to_attributes: (html_options, method) ->
|
47
|
+
if _.isString(method) and method.toLowerCase() isnt "get" and not /nofollow/.test(html_options["rel"])
|
48
|
+
html_options["rel"] = _.string.lstrip("#{html_options["rel"]} nofollow")
|
49
|
+
html_options["data-method"] = method
|
@@ -7,10 +7,10 @@
|
|
7
7
|
|
8
8
|
@DEBUG_MODE ?= false
|
9
9
|
@TEST_MODE ?= false
|
10
|
-
@
|
10
|
+
@LOG_TODO ?= true
|
11
11
|
|
12
12
|
@cout = =>
|
13
|
-
args =
|
13
|
+
args = _.toArray(arguments)
|
14
14
|
method = if args[0] in ['log', 'info', 'warn', 'error', 'assert', 'clear'] then args.shift() else 'log'
|
15
15
|
if @DEBUG_MODE and console?
|
16
16
|
method = console[method]
|
@@ -25,34 +25,53 @@
|
|
25
25
|
arguments[0]
|
26
26
|
|
27
27
|
@deprecate = (subject, instead = null) =>
|
28
|
-
@cout '
|
29
|
-
return
|
28
|
+
@cout 'error', "`#{subject}` DEPRECATED!#{if instead then " Use instead `#{instead}`" else ''}"
|
30
29
|
|
31
|
-
@
|
32
|
-
if @
|
33
|
-
@cout 'warn', "
|
34
|
-
return
|
30
|
+
@todo = (subject, location = null, numberOrString = null) =>
|
31
|
+
if @LOG_TODO
|
32
|
+
@cout 'warn', "TODO: #{subject}#{if location then " ### #{location}" else ''}#{if numberOrString then (if _.isNumber(numberOrString) then ":#{numberOrString}" else " > #{numberOrString}") else ''}"
|
35
33
|
|
36
34
|
@args = (a) ->
|
35
|
+
@deprecate 'arg()', '_.toArray()'
|
37
36
|
r = []
|
38
37
|
Array::push.apply(r, a) if a.length > 0
|
39
38
|
r
|
40
39
|
|
41
|
-
@
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
false
|
40
|
+
@logicalXOR = (a, b) ->
|
41
|
+
( a and not b ) or ( not a and b )
|
42
|
+
|
43
|
+
@bound = (number, min, max) ->
|
44
|
+
Math.max(min, Math.min(max, number))
|
45
|
+
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
|
48
|
+
@getParams = ->
|
49
|
+
q = location.search.substring(1).split('&')
|
50
|
+
r = {}
|
51
|
+
for e in q
|
52
|
+
t = e.split('=')
|
53
|
+
r[t[0]] = t[1]
|
54
|
+
r
|
55
|
+
|
56
|
+
@respondFormat = (url, format = null) ->
|
57
|
+
aq = url.split('?')
|
58
|
+
ah = aq[0].split('#')
|
59
|
+
ad = ah[0].split('.')
|
60
|
+
currentFormat = if ad.length > 1 and not /\//.test(ad[ad.length - 1]) then ad.pop() else ''
|
61
|
+
return currentFormat unless format?
|
62
|
+
return url if format is currentFormat
|
63
|
+
ad.push format if format
|
64
|
+
ah[0] = ad.join('.')
|
65
|
+
aq[0] = ah.join('#')
|
66
|
+
aq.join('?')
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
########### Deprecated ###########
|
53
71
|
|
54
72
|
# Helper function to get a value from a object as a property or as a function.
|
55
73
|
@getValue = (object, prop) ->
|
74
|
+
@deprecate "getValue()", "_.result()"
|
56
75
|
return null unless object and object[prop]
|
57
76
|
return if _.isFunction(object[prop]) then object[prop]() else object[prop]
|
58
77
|
|
@@ -80,16 +99,6 @@
|
|
80
99
|
r.push(e) for e in arrOrString when not _.include(r, e)
|
81
100
|
if isStr then r.join('') else r
|
82
101
|
|
83
|
-
@logicalXOR = (a, b) ->
|
84
|
-
( a and not b ) or ( not a and b )
|
85
|
-
|
86
|
-
@bound = (number, min, max) ->
|
87
|
-
Math.max(min, Math.min(max, number))
|
88
|
-
|
89
|
-
@roundWithPrecision = (number, precision = 2) ->
|
90
|
-
precision = Math.pow(10, precision)
|
91
|
-
Math.round(number * precision) / precision
|
92
|
-
|
93
102
|
@regexpSpace = /^\s*$/
|
94
103
|
@regexpTrim = /^\s*(.*?)\s*$/
|
95
104
|
|
@@ -97,53 +106,17 @@
|
|
97
106
|
@deprecate "strTrim(s)", "_.trim(s)"
|
98
107
|
s.match(@regexpTrim)[1]
|
99
108
|
|
100
|
-
# !!!!!!!!!!! tags !!!!!!!!!!!!
|
101
|
-
|
102
|
-
@number_to_currency = (number, units) ->
|
103
|
-
precision = 2
|
104
|
-
s = parseFloat(number).toFixed(precision)
|
105
|
-
b = s.length - 1 - precision
|
106
|
-
r = s.substring(b)
|
107
|
-
while b > 0
|
108
|
-
a = b - 3
|
109
|
-
r = ' ' + s.substring(a, b) + r
|
110
|
-
b = a
|
111
|
-
"#{r.substring(1)} #{units}"
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
@getParams = ->
|
116
|
-
q = location.search.substring(1).split('&')
|
117
|
-
r = {}
|
118
|
-
for e in q
|
119
|
-
t = e.split('=')
|
120
|
-
r[t[0]] = t[1]
|
121
|
-
r
|
122
|
-
|
123
|
-
@respondFormat = (url, format = null) ->
|
124
|
-
aq = url.split('?')
|
125
|
-
ah = aq[0].split('#')
|
126
|
-
ad = ah[0].split('.')
|
127
|
-
currentFormat = if ad.length > 1 and not /\//.test(ad[ad.length - 1]) then ad.pop() else ''
|
128
|
-
return currentFormat unless format?
|
129
|
-
return url if format is currentFormat
|
130
|
-
ad.push format if format
|
131
|
-
ah[0] = ad.join('.')
|
132
|
-
aq[0] = ah.join('#')
|
133
|
-
aq.join('?')
|
134
|
-
|
135
109
|
|
136
110
|
|
137
111
|
@rails_data = {}
|
138
112
|
|
139
113
|
@rails_scope = (controller_name, action_name, scopedCloasure = null, scopedCloasureArguments...) =>
|
114
|
+
@deprecate 'rails_scope'
|
140
115
|
return false if _.isString(controller_name) and controller_name isnt @rails_data['controller_name']
|
141
116
|
return false if _.isString(action_name) and action_name isnt @rails_data['action_name']
|
142
117
|
if _.isFunction(scopedCloasure)
|
143
118
|
arguments[2] scopedCloasureArguments...
|
144
119
|
true
|
145
120
|
|
146
|
-
|
147
|
-
|
148
121
|
$ =>
|
149
122
|
@rails_data = $('body').data()
|
File without changes
|
@@ -1,14 +1,20 @@
|
|
1
|
-
# TODO list
|
1
|
+
# TODO list:
|
2
2
|
# * load all locales
|
3
|
+
# * pluralize
|
3
4
|
|
4
|
-
@I18n
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
path =
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
@I18n = $.extend true,
|
6
|
+
{
|
7
|
+
locale: "en"
|
8
|
+
translations: {}
|
9
|
+
|
10
|
+
translate: (path, options = {}) ->
|
11
|
+
path = path.split('.') if _.isString(path)
|
12
|
+
scope = @translations
|
13
|
+
for step in path
|
14
|
+
scope = scope[step]
|
15
|
+
return options['default'] ? path.join('.') unless scope?
|
16
|
+
scope
|
17
|
+
|
18
|
+
t: -> @translate arguments...
|
19
|
+
|
20
|
+
}, @I18n
|
@@ -1,15 +1,16 @@
|
|
1
|
-
|
1
|
+
do ($ = jQuery) ->
|
2
2
|
|
3
3
|
# ========= max & min =========
|
4
4
|
$('input:text[data-gte], input:text[data-lte]').live 'change focusout blur', ->
|
5
|
-
jField = $
|
5
|
+
jField = $(@)
|
6
6
|
realValue = jField.val()
|
7
7
|
if realValue isnt ''
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
# TODO refactor this
|
9
|
+
min = parseFloat(jField.data('gte'))
|
10
|
+
max = parseFloat(jField.data('lte'))
|
11
|
+
oldValue = parseFloat(realValue)
|
11
12
|
v = oldValue
|
12
|
-
v = 0 if isNaN
|
13
|
+
v = 0 if isNaN(v)
|
13
14
|
v = min if not isNaN(min) and v < min
|
14
15
|
v = max if not isNaN(max) and v > max
|
15
16
|
jField.val(v).change() unless v is oldValue
|
@@ -33,15 +34,15 @@
|
|
33
34
|
'text' : /^.*$/
|
34
35
|
|
35
36
|
$.fn.getRegExpMask = ->
|
36
|
-
mask = @data
|
37
|
+
mask = @data('regexpMask')
|
37
38
|
if _.isString(mask)
|
38
39
|
try
|
39
|
-
mask = new RegExp
|
40
|
+
mask = new RegExp(mask)
|
40
41
|
@data 'regexpMask', mask
|
41
42
|
catch e
|
42
43
|
# nop
|
43
44
|
else
|
44
|
-
dataType = @data
|
45
|
+
dataType = @data('dataType')
|
45
46
|
mask = $.regexp.typedField[dataType] if dataType
|
46
47
|
unless mask
|
47
48
|
@val 'unknown dataType'
|
@@ -56,18 +57,16 @@
|
|
56
57
|
|
57
58
|
$.fn.setRegExpMask = (mask) ->
|
58
59
|
stringMask = 'true'
|
59
|
-
if _.isString
|
60
|
+
if _.isString(mask)
|
60
61
|
stringMask = mask
|
61
62
|
try
|
62
|
-
mask = new RegExp
|
63
|
+
mask = new RegExp(mask)
|
63
64
|
catch e
|
64
65
|
# nop
|
65
|
-
if _.isRegExp
|
66
|
+
if _.isRegExp(mask)
|
66
67
|
@
|
67
68
|
.dropRegExpMask()
|
68
69
|
.attr('data-regexp-mask', stringMask)
|
69
70
|
.data('regexpMask', mask)
|
70
71
|
.change()
|
71
72
|
@
|
72
|
-
|
73
|
-
)( jQuery )
|
@@ -1,14 +1,4 @@
|
|
1
|
-
|
2
|
-
* front-end ui-components routines
|
3
|
-
*
|
4
|
-
* @version 0.5.5.alpha / 2010-2012
|
5
|
-
* @author Karpunin Dmitry / Evrone.com
|
6
|
-
* @email koderfunk_at_gmail_dot_com
|
7
|
-
*
|
8
|
-
* TODO register components
|
9
|
-
* TODO using underscore.js
|
10
|
-
*
|
11
|
-
###
|
1
|
+
# TODO: register components
|
12
2
|
|
13
3
|
do ($ = jQuery) =>
|
14
4
|
|
@@ -18,43 +8,39 @@ do ($ = jQuery) =>
|
|
18
8
|
|
19
9
|
@ror_id = (jObjOrString) ->
|
20
10
|
if jObjOrString instanceof jQuery
|
21
|
-
id = jObjOrString.data(
|
22
|
-
unless id
|
23
|
-
id = jObjOrString.attr(
|
24
|
-
if id
|
25
|
-
|
26
|
-
|
27
|
-
jObjOrString.data 'rorId', id
|
28
|
-
id
|
29
|
-
else
|
30
|
-
null
|
31
|
-
else
|
11
|
+
id = jObjOrString.data("rorId") # Maybe use "id"
|
12
|
+
unless id?
|
13
|
+
id = ror_id(jObjOrString.attr("id"))
|
14
|
+
jObjOrString.data("rorId", id) if id?
|
15
|
+
id
|
16
|
+
else if _.isString(jObjOrString)
|
32
17
|
matchResult = jObjOrString.match($.regexp.rorId)
|
33
18
|
if matchResult then matchResult[2] else null
|
19
|
+
else
|
20
|
+
null
|
34
21
|
|
35
|
-
$.fn.rorId = ->
|
22
|
+
$.fn.rorId = (id = null, prefix = null) ->
|
36
23
|
if arguments.length
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
24
|
+
jThis = @first()
|
25
|
+
thisId = @attr("id")
|
26
|
+
if not prefix? and _.isString(thisId)
|
27
|
+
prefix = matchResult[1] if matchResult = thisId.match($.regexp.rorId)
|
28
|
+
@data("rorId", id)
|
29
|
+
if prefix?
|
30
|
+
jThis.attr "id", "#{prefix}_#{id}"
|
31
|
+
jThis
|
44
32
|
else
|
45
33
|
ror_id @
|
46
34
|
|
47
35
|
$.fn.getClasses = ->
|
48
|
-
_.words @attr("class")
|
36
|
+
_.string.words @attr("class")
|
49
37
|
|
50
38
|
# Get hash of html-dom attributes from first matched element or false, if no elements
|
51
39
|
$.fn.getAttributes = ->
|
40
|
+
attrs = {}
|
52
41
|
if @length
|
53
|
-
attrs =
|
54
|
-
|
55
|
-
attrs
|
56
|
-
else
|
57
|
-
false
|
42
|
+
attrs[attr.nodeName] = attr.nodeValue for attr in this[0].attributes
|
43
|
+
attrs
|
58
44
|
|
59
45
|
# [showOrHide[, duration[, callback]]]
|
60
46
|
$.fn.slideToggleByState = ->
|
@@ -74,7 +60,8 @@ do ($ = jQuery) =>
|
|
74
60
|
$.isHTML = (content, strong = false) ->
|
75
61
|
return false unless _.isString(content)
|
76
62
|
matches = content.match($.regexp.HTML)
|
77
|
-
|
63
|
+
return false unless matches?
|
64
|
+
not strong or matches[1] is matches[2]
|
78
65
|
|
79
66
|
# TODO replace usages to underscore methods and using distribution
|
80
67
|
unless $.isRegExp
|
@@ -6,16 +6,17 @@
|
|
6
6
|
|
7
7
|
( function( _, undefined )
|
8
8
|
{
|
9
|
+
var
|
10
|
+
plurals = [ ],
|
11
|
+
|
12
|
+
singulars = [ ],
|
13
|
+
|
14
|
+
uncountables = [ ];
|
15
|
+
|
9
16
|
/**
|
10
17
|
* Inflector
|
11
18
|
*/
|
12
19
|
var inflector = {
|
13
|
-
|
14
|
-
plurals : [ ],
|
15
|
-
|
16
|
-
singulars : [ ],
|
17
|
-
|
18
|
-
uncountables : [ ],
|
19
20
|
|
20
21
|
gsub : function( word, rule, replacement )
|
21
22
|
{
|
@@ -26,7 +27,7 @@
|
|
26
27
|
|
27
28
|
plural : function( rule, replacement )
|
28
29
|
{
|
29
|
-
|
30
|
+
plurals.unshift( [ rule, replacement ] );
|
30
31
|
},
|
31
32
|
|
32
33
|
pluralize : function( word, count, includeNumber )
|
@@ -40,14 +41,14 @@
|
|
40
41
|
}
|
41
42
|
else
|
42
43
|
{
|
43
|
-
if( _(
|
44
|
+
if( _( uncountables ).include( word ) )
|
44
45
|
{
|
45
46
|
return word;
|
46
47
|
}
|
47
48
|
|
48
49
|
result = word;
|
49
50
|
|
50
|
-
_(
|
51
|
+
_( plurals ).detect( function( rule )
|
51
52
|
{
|
52
53
|
var gsub = this.gsub( word, rule[ 0 ], rule[ 1 ] );
|
53
54
|
|
@@ -61,19 +62,19 @@
|
|
61
62
|
|
62
63
|
singular : function( rule, replacement )
|
63
64
|
{
|
64
|
-
|
65
|
+
singulars.unshift( [ rule, replacement ] );
|
65
66
|
},
|
66
67
|
|
67
68
|
singularize : function( word )
|
68
69
|
{
|
69
|
-
if( _(
|
70
|
+
if( _( uncountables ).include( word ) )
|
70
71
|
{
|
71
72
|
return word;
|
72
73
|
}
|
73
74
|
|
74
75
|
var result = word;
|
75
76
|
|
76
|
-
_(
|
77
|
+
_( singulars ).detect( function( rule )
|
77
78
|
{
|
78
79
|
var gsub = this.gsub( word, rule[ 0 ], rule[ 1 ] );
|
79
80
|
|
@@ -86,20 +87,20 @@
|
|
86
87
|
|
87
88
|
irregular : function( singular, plural )
|
88
89
|
{
|
89
|
-
this.plural( singular, plural );
|
90
|
-
this.singular( plural, singular );
|
90
|
+
this.plural( '\\b' + singular + '\\b', plural );
|
91
|
+
this.singular( '\\b' + plural + '\\b', singular );
|
91
92
|
},
|
92
93
|
|
93
94
|
uncountable : function( word )
|
94
95
|
{
|
95
|
-
|
96
|
+
uncountables.unshift( word );
|
96
97
|
},
|
97
98
|
|
98
99
|
resetInflections : function( )
|
99
100
|
{
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
plurals = [ ];
|
102
|
+
singulars = [ ];
|
103
|
+
uncountables = [ ];
|
103
104
|
|
104
105
|
this.plural( /$/, 's' );
|
105
106
|
this.plural( /s$/, 's' );
|