ultimate-base 0.2.3.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ultimate-base (0.2.3.2)
4
+ ultimate-base (0.2.4)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/LICENSE CHANGED
@@ -1,5 +1,19 @@
1
- Dual licensed under the MIT and GPL licenses:
2
- http://www.opensource.org/licenses/mit-license.php
3
- http://www.gnu.org/licenses/gpl.html
1
+ Copyright (c) 2011-2012 Dmitry Karpunin (aka KODer) koderfunk@gmail.com
4
2
 
5
- Copyright (c) 2010-2012 Dmitry KODer Karpunun / Evrone.com
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1 +1,25 @@
1
1
  Ultimate UI core, base helpers and improves for Ruby on Rails Front-end
2
+
3
+ ## Licence ##
4
+
5
+ The MIT License
6
+
7
+ Copyright (c) 2010-2012 Dmitry Karpunin (aka KODer) koderfunk@gmail.com
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
@@ -20,10 +20,11 @@ do ($ = jQuery) ->
20
20
 
21
21
  $.fn.getView = (viewClass, inheritance = false) ->
22
22
  if _.isString(viewClass)
23
- for o in @
24
- views = $(o).data("views") or []
25
- for view in views
26
- return view if view.constructor.className is viewClass
23
+ deprecate "getView() with viewClass as string", "viewClass as Backbone.View inheritor"
24
+ # for o in @
25
+ # views = $(o).data("views") or []
26
+ # for view in views
27
+ # return view if view.constructor.className is viewClass
27
28
  else if Ultimate.Backbone.isViewClass(viewClass)
28
29
  for o in @
29
30
  views = $(o).data("views") or []
@@ -37,8 +38,9 @@ do ($ = jQuery) ->
37
38
 
38
39
  $.fn.hasView = (viewClass) ->
39
40
  if _.isString(viewClass)
40
- for o in @
41
- return true if _.any $(o).data("views") or [], (w) -> w.constructor.className is viewClass
41
+ deprecate "hasView() with viewClass as string", "viewClass as Backbone.View inheritor"
42
+ # for o in @
43
+ # return true if _.any $(o).data("views") or [], (w) -> w.constructor.className is viewClass
42
44
  else if Ultimate.Backbone.isViewClass(viewClass)
43
45
  for o in @
44
46
  return true if _.any $(o).data("views") or [], (w) -> w.constructor is viewClass
@@ -25,7 +25,7 @@ do ($ = jQuery) ->
25
25
  else
26
26
  return view if _returnView
27
27
  return jContainer unless argsLength
28
- command = "updateSettings"
28
+ command = "_configure"
29
29
  if view[command]
30
30
  return getValue(view, command)
31
31
  else
@@ -39,28 +39,22 @@ do ($ = jQuery) ->
39
39
  if _returnView then view else jContainer
40
40
 
41
41
 
42
- # TODO rewrite docs
43
- ###
44
- * Invoke Ultimate Flash functionality for the first element in the set of matched elements.
42
+ ###*
43
+ * Make $.fn.pluginName() as wrapper under Backbone.View.
44
+ * First call on jQuery object invoke View functionality for the first element in the set of matched elements.
45
+ * Subsequent calls forwarding on view methods or return view property.
45
46
  * If last argument {Boolean} true, then returns {View}.
46
47
  * @usage
47
- *** standart actions ***
48
- * construction .ultimateFlash([Object options = {}]) ~ {jQuery} jContainer
49
- * show .ultimateFlash("show", String type, String text) ~ {jQuery} jFlash | {Boolean} false
50
- * notice .ultimateFlash("notice", String text) ~ {jQuery} jFlash | {Boolean} false
51
- * alert .ultimateFlash("alert", String text) ~ {jQuery} jFlash | {Boolean} false
52
- *** extended actions ***
53
- * getSettings .ultimateFlash("getSettings") ~ {Object} settings
54
- * setSettings .ultimateFlash("setSettings", {Object} settings) ~ {jQuery} jContainer
55
- * updateSettings .ultimateFlash({Object} options) ~ {Object} settings
56
- * auto .ultimateFlash("auto", {ArrayOrObject} obj) ~ {Array} ajFlashes | {Boolean} false
57
- * ajaxSuccess .ultimateFlash("ajaxSuccess"[, Arguments successArgs = []])
58
- * ajaxError .ultimateFlash("ajaxError"[, String text = settings.translations.defaultErrorText][, Arguments errorArgs = []])
48
+ * construction .pluginName([Object options = {}]) : {jQuery} jContainer
49
+ * updateOptions .pluginName({Object} options) : {Object} view options
50
+ * get options .pluginName("options") : {Object} view options
51
+ * some method .pluginName("methodName", *methodArguments) : {jQuery} chanin object || {AnotherType} method result
59
52
  ###
60
53
 
61
54
  Ultimate.Backbone.createJQueryPlugin = (pluginName, viewClass) ->
62
- cout "info", "Ultimate.Backbone.createJQueryPlugin", pluginName, viewClass
55
+ Ultimate.Backbone.debug ".createJQueryPlugin()", pluginName, viewClass
63
56
  if Ultimate.Backbone.isViewClass(viewClass)
57
+ viewClass.pluginName = pluginName
64
58
  jQuery.fn[pluginName] = -> @ultimateBackboneViewPluginAdapter pluginName, viewClass, arguments
65
59
  else
66
60
  jQuery.error "Second argument of Ultimate.Backbone.createJQueryPlugin() must be View class inherited from Backbone.View"
@@ -2,7 +2,12 @@
2
2
 
3
3
  class Ultimate.Backbone.View extends Backbone.View
4
4
 
5
- viewOptions: []
5
+ @defaultLocales:
6
+ en: {}
7
+ ru: {}
8
+
9
+ locale: "en"
10
+ translations: {}
6
11
 
7
12
  loadingState: null
8
13
  loadingWidthMethodName: "innerWidth"
@@ -10,6 +15,8 @@ class Ultimate.Backbone.View extends Backbone.View
10
15
  loadingStateClass: "loading"
11
16
  loadingOverlayClass: "loading-overlay"
12
17
 
18
+ viewOptions: -> []
19
+
13
20
  constructor: ->
14
21
  Ultimate.Backbone.debug ".View.constructor()", @
15
22
  super
@@ -77,12 +84,41 @@ class Ultimate.Backbone.View extends Backbone.View
77
84
  # Overload parent method Backbone.View._configure() as hook for reflectOptions().
78
85
  _configure: (options) ->
79
86
  super
87
+ @initTranslations()
80
88
  @reflectOptions()
81
89
 
82
- reflectOptions: (viewOptions, options = @options) ->
83
- viewOptions = getValue(@, "viewOptions") unless viewOptions
84
- @[attr] = options[attr] for attr in viewOptions when options[attr]
90
+ reflectOptions: (viewOptions = getValue(@, "viewOptions"), options = @options) ->
91
+ @[attr] = options[attr] for attr in viewOptions when typeof options[attr] isnt "undefined"
92
+ @[attr] = value for attr, value of options when typeof @[attr] isnt "undefined"
93
+ @
85
94
 
95
+ updateOptions: (options) ->
96
+ @_configure(options)
97
+ @options
98
+
99
+ # use I18n, and modify locale and translations in options
100
+ # modify and return merged data
101
+ initTranslations: (options = @options) ->
102
+ # if global compatible I18n
103
+ if I18n? and I18n.locale and I18n.t
104
+ options["locale"] ||= I18n.locale
105
+ if options["locale"] is I18n.locale
106
+ # pointing to defaults locales of language specified in I18n
107
+ _defaultLocales = @constructor.defaultLocales?[I18n.locale] ||= {}
108
+ unless _defaultLocales["loaded"]
109
+ _defaultLocales["loaded"] = true
110
+ # try read localized strings
111
+ if _localesFromI18n = I18n.t(options["i18nKey"] or _.underscored(@constructor.pluginName or @constructor.name))
112
+ # fill it from I18n
113
+ _.extend _defaultLocales, _localesFromI18n
114
+ @locale = options["locale"] if options["locale"]
115
+ translations = if @locale then @constructor.defaultLocales?[@locale] or {} else {}
116
+ $.extend true, options, translations: translations, options
117
+ options
118
+
119
+ t: (key) ->
120
+ # TODO maybe use I18n there
121
+ @translations[key]
86
122
 
87
123
 
88
124
  # Overloadable getter for jQuery-container that will be blocked.
@@ -14,7 +14,7 @@ class Ultimate.Backbone.Views.Slider extends Ultimate.Backbone.View
14
14
  events: ->
15
15
  "click .nav.enabled" : "navClick"
16
16
 
17
- viewOptions: ["vertical", "cycling", "interval", "durationPerPixel", "prevItems"]
17
+ viewOptions: -> _.union super, ["vertical", "cycling", "interval", "durationPerPixel", "prevItems"]
18
18
 
19
19
  vertical: false
20
20
  cycling: false
@@ -1,8 +1,9 @@
1
+ #= require ../view
1
2
  #= require ultimate/improves/typed-fields
2
3
 
3
- Ultimate.Backbone.Views ||= {}
4
+ Ultimate.Backbone.Observers ||= {}
4
5
 
5
- class Ultimate.Backbone.Views.TypedFields extends Ultimate.Backbone.View
6
+ class Ultimate.Backbone.Observers.TypedFields extends Ultimate.Backbone.View
6
7
 
7
8
  selector: "input:text[data-data-type], input:text[data-regexp-mask]"
8
9
 
@@ -37,4 +38,4 @@ class Ultimate.Backbone.Views.TypedFields extends Ultimate.Backbone.View
37
38
 
38
39
 
39
40
 
40
- Ultimate.Backbone.createJQueryPlugin? "typedFields", Ultimate.Backbone.Views.TypedFields
41
+ Ultimate.Backbone.createJQueryPlugin? "typedFields", Ultimate.Backbone.Observers.TypedFields
@@ -1,7 +1,7 @@
1
1
  ###
2
2
  * front-end ui-components routines
3
3
  *
4
- * @version 0.5.5.alpha / 2010-2011
4
+ * @version 0.5.5.alpha / 2010-2012
5
5
  * @author Karpunin Dmitry / Evrone.com
6
6
  * @email koderfunk_at_gmail_dot_com
7
7
  *
@@ -10,53 +10,48 @@
10
10
  *
11
11
  ###
12
12
 
13
- # TODO do ($ = jQuery) =>
14
- ( ($) =>
13
+ do ($ = jQuery) =>
15
14
 
16
15
  $.regexp ||= {}
17
16
 
18
17
  $.regexp.rorId ||= /(\w+)_(\d+)$/
19
18
 
20
19
  @ror_id = (jObjOrString) ->
21
- if isJQ jObjOrString
22
- id = jObjOrString.data 'rorId'
20
+ if jObjOrString instanceof jQuery
21
+ id = jObjOrString.data('rorId') # Maybe use "id"
23
22
  unless id
24
- id = jObjOrString.attr 'id'
23
+ id = jObjOrString.attr('id')
25
24
  if id
26
- matchResult = id.match $.regexp.rorId
27
- id = if matchResult then matchResult[2] else ''
25
+ matchResult = id.match($.regexp.rorId)
26
+ id = if matchResult then matchResult[2] else null
28
27
  jObjOrString.data 'rorId', id
28
+ id
29
29
  else
30
- id = ''
30
+ null
31
31
  else
32
- matchResult = jObjOrString.match $.regexp.rorId
33
- id = if matchResult then matchResult[2] else ''
34
- id
32
+ matchResult = jObjOrString.match($.regexp.rorId)
33
+ if matchResult then matchResult[2] else null
35
34
 
36
35
  $.fn.rorId = ->
37
36
  if arguments.length
38
37
  id = arguments[0]
39
38
  word = 'ror_id'
40
- thisId = @attr 'id'
39
+ thisId = @attr('id')
41
40
  if thisId
42
- word = matchResult[1] if matchResult = thisId.match $.regexp.rorId
43
- @data('rorId', id).attr 'id', word + '_' + id
41
+ word = matchResult[1] if matchResult = thisId.match($.regexp.rorId)
42
+ @data('rorId', id).attr 'id', "${word}_#{id}"
44
43
  @
45
44
  else
46
45
  ror_id @
47
46
 
48
47
  $.fn.getClasses = ->
49
- return [] unless @length
50
- classAttr = $.trim @attr 'class'
51
- if classAttr then classAttr.split(/\s+/) else []
48
+ _.words @attr("class")
52
49
 
53
50
  # Get hash of html-dom attributes from first matched element or false, if no elements
54
51
  $.fn.getAttributes = ->
55
52
  if @length
56
53
  attrs = {}
57
- #TRY attrs[attr.nodeName] = attr.nodeValue for attr in this[0].attributes
58
- $.each this[0].attributes, (index, attr) ->
59
- attrs[attr.nodeName] = attr.nodeValue
54
+ attrs[attr.nodeName] = attr.nodeValue for attr in this[0].attributes
60
55
  attrs
61
56
  else
62
57
  false
@@ -65,7 +60,7 @@
65
60
  $.fn.slideToggleByState = ->
66
61
  if @length
67
62
  if arguments.length > 0
68
- a = args arguments
63
+ a = args(arguments)
69
64
  if a.shift()
70
65
  @slideDown.apply @, a
71
66
  else
@@ -74,6 +69,13 @@
74
69
  @slideToggle()
75
70
  @
76
71
 
72
+ unless $.isHTML
73
+ $.regexp.HTML = /^\s*<(\w+)[\S\s]*<\/(\w+)>\s*$/
74
+ $.isHTML = (content, strong = false) ->
75
+ return false unless _.isString(content)
76
+ matches = content.match($.regexp.HTML)
77
+ matches and not strong or matches[1] is matches[2]
78
+
77
79
  # TODO replace usages to underscore methods and using distribution
78
80
  unless $.isRegExp
79
81
  $.isRegExp = (candidate) ->
@@ -90,14 +92,7 @@
90
92
  deprecate '$.isString', '_.isString'
91
93
  typeof v is "string"
92
94
 
93
- unless $.isHTML
94
- $.regexp.HTML = new RegExp "^\\s*<(\\w+)[\\S\\s]*</(\\w+)>\\s*$"
95
- $.isHTML = (v) ->
96
- matches = $.regexp.HTML.exec v
97
- matches and matches[1] is matches[2]
98
-
99
95
  if typeof $.isEmptyString is "undefined"
100
96
  $.isEmptyString = (v) ->
97
+ deprecate '$.isEmptyString', '_.isBlank'
101
98
  regexpSpace.test v
102
-
103
- )( jQuery )
@@ -10,39 +10,39 @@
10
10
  @WARNINGS ?= true
11
11
 
12
12
  @cout = =>
13
- args = @args arguments
13
+ args = @args(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]
17
17
  if method.apply?
18
- method.apply console, args
18
+ method.apply(console, args)
19
19
  else
20
- method args
20
+ method(args)
21
21
  return args[0]
22
22
 
23
23
  @_cout = =>
24
- console.log arguments if console?
24
+ console.log(arguments) if console?
25
25
  arguments[0]
26
26
 
27
27
  @deprecate = (subject, instead = null) =>
28
- @cout 'warn', "\"#{subject}\" DEPRECATED!" + if instead then " Use instead: \"#{instead}\"" else ''
28
+ @cout 'warn', "\"#{subject}\" DEPRECATED!#{if instead then " Use instead: \"#{instead}\"" else ''}"
29
29
  return
30
30
 
31
31
  @warning = (subject, instead = null) =>
32
32
  if @WARNINGS
33
- @cout 'warn', "\"#{subject}\" WARNING!" + if instead then " Use instead: \"#{instead}\"" else ''
33
+ @cout 'warn', "\"#{subject}\" WARNING!#{if instead then " Use instead: \"#{instead}\"" else ''}"
34
34
  return
35
35
 
36
36
  @args = (a) ->
37
37
  r = []
38
- Array::push.apply r, a if a.length > 0
38
+ Array::push.apply(r, a) if a.length > 0
39
39
  r
40
40
 
41
41
  @blockGiven = (args) =>
42
42
  l = args.length
43
43
  if l
44
44
  l = args[l - 1]
45
- if _.isFunction l then l else false
45
+ if _.isFunction(l) then l else false
46
46
  else
47
47
  false
48
48
 
@@ -57,53 +57,53 @@
57
57
  return if _.isFunction(object[prop]) then object[prop]() else object[prop]
58
58
 
59
59
  @isset = (obj) =>
60
- @deprecate 'isset(obj)', 'obj isnt undefined" OR "obj?'
60
+ @deprecate 'isset(obj)', '_.isUndefined(obj) OR "obj isnt undefined" OR "obj?'
61
61
  obj isnt undefined
62
62
 
63
63
  @isString = (v) =>
64
- @deprecate 'isString(v)', '_.isString v'
64
+ @deprecate 'isString(v)', '_.isString(v)'
65
65
  _.isString v
66
66
 
67
67
  @isNumber = (v) =>
68
- @deprecate 'isNumber(v)', '_.isNumber v'
69
- not isNaN parseInt v
68
+ @deprecate 'isNumber(v)', '_.isNumber(v)'
69
+ not isNaN(parseInt(v))
70
70
 
71
71
  @isJQ = (obj) ->
72
72
  @deprecate 'isJQ(obj)', 'obj instanceof jQuery'
73
- _.isObject(obj) and _.isString obj.jquery
73
+ _.isObject(obj) and _.isString(obj.jquery)
74
74
 
75
75
  @uniq = (arrOrString) ->
76
- @deprecate 'uniq(a)', '_.uniq a'
77
- isStr = _.isString arrOrString
78
- return arrOrString unless isStr or _.isArray arrOrString
76
+ @deprecate 'uniq(a)', '_.uniq(a)'
77
+ isStr = _.isString(arrOrString)
78
+ return arrOrString unless isStr or _.isArray(arrOrString)
79
79
  r = []
80
- r.push e for e in arrOrString when not _.include r, e
81
- if isStr then r.join '' else r
80
+ r.push(e) for e in arrOrString when not _.include(r, e)
81
+ if isStr then r.join('') else r
82
82
 
83
83
  @logicalXOR = (a, b) ->
84
84
  ( a and not b ) or ( not a and b )
85
85
 
86
86
  @bound = (number, min, max) ->
87
- Math.max min, Math.min number, max
87
+ Math.max(min, Math.min(max, number))
88
88
 
89
89
  @roundWithPrecision = (number, precision = 2) ->
90
- precision = Math.pow 10, precision
90
+ precision = Math.pow(10, precision)
91
91
  Math.round(number * precision) / precision
92
92
 
93
- @regexpSpace = new RegExp '^\\s*$'
94
- @regexpTrim = new RegExp '^\\s*(.*?)\\s*$'
93
+ @regexpSpace = /^\s*$/
94
+ @regexpTrim = /^\s*(.*?)\s*$/
95
95
 
96
96
  @strTrim = (s) =>
97
- @deprecate "strTrim(s)", "$.trim(s)"
97
+ @deprecate "strTrim(s)", "_.trim(s)"
98
98
  s.match(@regexpTrim)[1]
99
99
 
100
100
  # !!!!!!!!!!! tags !!!!!!!!!!!!
101
101
 
102
102
  @number_to_currency = (number, units) ->
103
103
  precision = 2
104
- s = parseFloat(number).toFixed precision
104
+ s = parseFloat(number).toFixed(precision)
105
105
  b = s.length - 1 - precision
106
- r = s.substring b
106
+ r = s.substring(b)
107
107
  while b > 0
108
108
  a = b - 3
109
109
  r = ' ' + s.substring(a, b) + r
@@ -113,24 +113,24 @@
113
113
 
114
114
 
115
115
  @getParams = ->
116
- q = location.search.substring(1).split '&'
116
+ q = location.search.substring(1).split('&')
117
117
  r = {}
118
118
  for e in q
119
- t = e.split '='
119
+ t = e.split('=')
120
120
  r[t[0]] = t[1]
121
121
  r
122
122
 
123
123
  @respondFormat = (url, format = null) ->
124
- aq = url.split '?'
125
- ah = aq[0].split '#'
126
- ad = ah[0].split '.'
124
+ aq = url.split('?')
125
+ ah = aq[0].split('#')
126
+ ad = ah[0].split('.')
127
127
  currentFormat = if ad.length > 1 and not /\//.test(ad[ad.length - 1]) then ad.pop() else ''
128
128
  return currentFormat unless format?
129
129
  return url if format is currentFormat
130
130
  ad.push format if format
131
- ah[0] = ad.join '.'
132
- aq[0] = ah.join '#'
133
- aq.join '?'
131
+ ah[0] = ad.join('.')
132
+ aq[0] = ah.join('#')
133
+ aq.join('?')
134
134
 
135
135
 
136
136
 
@@ -139,7 +139,7 @@
139
139
  @rails_scope = (controller_name, action_name, scopedCloasure = null, scopedCloasureArguments...) =>
140
140
  return false if _.isString(controller_name) and controller_name isnt @rails_data['controller_name']
141
141
  return false if _.isString(action_name) and action_name isnt @rails_data['action_name']
142
- if _.isFunction scopedCloasure
142
+ if _.isFunction(scopedCloasure)
143
143
  arguments[2] scopedCloasureArguments...
144
144
  true
145
145