src/util.coffee in luca-0.9.6 vs src/util.coffee in luca-0.9.7
- old
+ new
@@ -34,10 +34,20 @@
prefix = parts.shift()
parts = _( parts ).map (p)-> _.string.capitalize(p)
fn = prefix + parts.join('')
+Luca.util.toCssClass = (componentName, exclusions...)->
+ parts = componentName.split('.')
+
+ transformed = for part in parts when _( exclusions ).indexOf(part) is -1
+ part = _.str.underscored(part)
+ part = part.replace(/_/g,'-')
+ part
+
+ transformed.join '-'
+
Luca.util.isIE = ()->
try
Object.defineProperty({}, '', {})
return false
catch e
@@ -115,6 +125,43 @@
# valid types are success, warning, important, info, inverse
Luca.util.badge = (contents="", type, baseClass="badge")->
cssClass = baseClass
cssClass += " #{ baseClass }-#{ type }" if type?
Luca.util.make("span",{class:cssClass},contents)
+
+Luca.util.setupHooks = (set)->
+ set ||= @hooks
+
+ _(set).each (eventId)=>
+ fn = Luca.util.hook( eventId )
+
+ callback = ()->
+ @[fn]?.apply @, arguments
+
+ callback = _.once(callback) if eventId?.match(/once:/)
+
+ @on eventId, callback, @
+
+Luca.util.setupHooksAdvanced = (set)->
+ set ||= @hooks
+
+ _(set).each (eventId)=>
+ hookSetup = @[ Luca.util.hook( eventId ) ]
+
+ unless _.isArray(hookSetup)
+ hookSetup = [hookSetup]
+
+ for entry in hookSetup
+ fn = if _.isString(entry)
+ @[ entry ]
+
+ if _.isFunction(entry)
+ fn = entry
+
+ callback = ()->
+ @[fn]?.apply @, arguments
+
+ if eventId?.match(/once:/)
+ callback = _.once(callback)
+
+ @on eventId, callback, @