app/assets/javascripts/ultimate/jquery-plugin-class.js.coffee in ultimate-base-0.5.0.0 vs app/assets/javascripts/ultimate/jquery-plugin-class.js.coffee in ultimate-base-0.6.0
- old
+ new
@@ -1,6 +1,5 @@
-# TODO simlify translations infrastructure
# `pluginClass` must store propery `$el` as jQuery object wrapped on the target DOM-object in his instance.
#= require ./base
# TODO minimize requirements
@@ -12,11 +11,10 @@
# 1 _.isString
# 1 _.isArray
# 1 _.bind
# 1 _.clone
# 1 _.outcasts.delete
-# 1 _.string.underscored
# 1 _.string.startsWith
class Ultimate.Plugin
cid: null
el: null
@@ -24,14 +22,10 @@
nodes: null
events: null
options: null
- # @defaultLocales: { en: {} }
- locale: 'en'
- translations: null
-
constructor: (options) ->
@cid = _.uniqueId('ultimatePlugin_')
@_configure options
@$el = $(@el).first()
@el = @$el[0]
@@ -69,11 +63,11 @@
args = _.toArray(arguments)
args[0] = @_normalizeEvents(events)
@_delegateEvents args...
# delegateEvents() from backbone.js
- _delegateEvents: (events = _.result(@, "events")) ->
+ _delegateEvents: (events = _.result(@, 'events')) ->
return unless events
@undelegateEvents()
for key, method of events
method = @[events[key]] unless _.isFunction(method)
throw new Error("Method \"#{events[key]}\" does not exist") unless method
@@ -84,11 +78,11 @@
@$el.bind(eventName, method)
else
@$el.delegate(selector, eventName, method)
_normalizeEvents: (events) ->
- events = _.result(@, "events") unless events
+ events = _.result(@, 'events') unless events
if events
normalizedEvents = {}
for key, method of events
[[], eventName, selector] = key.match(delegateEventSplitter)
selector = _.result(@, selector)
@@ -101,27 +95,11 @@
events
_configure: (options = {}) ->
@options ||= {}
_.extend @options, options
- #cout '@options', @options
@_reflectOptions()
- @_initTranslations()
- _reflectOptions: (reflectableOptions = _.result(@, "reflectableOptions"), options = @options) ->
+ _reflectOptions: (reflectableOptions = _.result(@, 'reflectableOptions'), options = @options) ->
if _.isArray(reflectableOptions)
@[attr] = options[attr] for attr in reflectableOptions when not _.isUndefined(options[attr])
@[attr] = value for attr, value of options when not _.isUndefined(@[attr])
-
- # use I18n, and modify locale and translations
- _initTranslations: ->
- @translations ||= {}
- if @constructor.defaultLocales?
- if not @options["locale"] and I18n?.locale of @constructor.defaultLocales
- @locale = I18n.locale
- #cout '!!!Set LOCALE FROM I18N ', @locale
- defaultTranslations = if @locale then @constructor.defaultLocales[@locale] or {} else {}
- #cout '!!!defaultTranslations', @locale, defaultTranslations
- _.defaults @translations, defaultTranslations
-
- t: (key) ->
- @translations[key] or _.string.humanize(key)