$.extend decko, # returns full path with slot parameters slotPath: (path, slot)-> xtra = {} main = $('#main').children('.card-slot').data 'cardName' xtra['main'] = main if main? if slot xtra['is_main'] = true if slot.isMain() slotdata = slot.data 'slot' decko.slotParams slotdata, xtra, 'slot' if slotdata? decko.path(path) + ( (if path.match /\?/ then '&' else '?') + $.param(xtra) ) slotParams: (raw, processed, prefix)-> $.each raw, (key, value)-> cgiKey = prefix + '[' + snakeCase(key) + ']' if key == 'items' decko.slotParams value, processed, cgiKey else processed[cgiKey] = value slotReady: (func)-> $('document').ready -> $('body').on 'slotReady', '.card-slot', (e) -> e.stopPropagation() func.call this, $(this) jQuery.fn.extend { slot: (status="success") -> if @data("slot-#{status}-selector") @findSlot(@data("slot-#{status}-selector")) else if @data("slot-selector") @findSlot(@data("slot-selector")) else @closest '.card-slot' isSlot: -> $(this).hasClass "card-slot" isMain: -> @slot().parent('#main')[0] findSlot: (selector) -> target_slot = @closest(selector) parent_slot = @closest '.card-slot' # if slot-selector doesn't apply to a child, search in all parent slots and finally in the body while target_slot.length == 0 and parent_slot.length > 0 target_slot = $(parent_slot).find(selector) parent_slot = $(parent_slot).parent().closest '.card-slot' if target_slot.length == 0 $(selector) else target_slot updateSlot: (url) -> $slot = $(this) $slot = $slot.slot() unless $slot.isSlot unless url? path = '~' + $slot.data('cardId') + "?view=" + $slot.data("slot")["view"] url = decko.slotPath path, $slot $slot.addClass 'slotter' $slot.attr 'href', url $.rails.handleRemote($slot) setSlotContent: (val, overlay=false) -> s = @slot() v = $(val) unless v[0] # if slotdata = s.attr 'data-slot' # v.attr 'data-slot', slotdata if slotdata? # else #simple text (not html) v = val if v.hasClass("_overlay") s.wrapAll('