mod/machines/lib/javascript/decko_slot.js.coffee in card-1.97.0 vs mod/machines/lib/javascript/decko_slot.js.coffee in card-1.97.0.1

- old
+ new

@@ -38,29 +38,44 @@ @closest(".card-slot") selectSlot: (selectorName) -> if selector = @data(selectorName) slot = @findSlot selector - slot[0] && slot + slot && slot[0] && slot isSlot: -> $(this).hasClass "card-slot" isMain: -> @slot().parent('#main')[0] findSlot: (selector) -> - target_slot = @closest(selector) - parent_slot = @closest '.card-slot' + if selector == "modal-origin" + @findOriginSlot("modal") + else if selector == "overlay-origin" + @findOriginSlot("overlay") + else + 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) + # 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 + + # type can be "modal" or "overlay" + findOriginSlot: (type) -> + overlaySlot = @closest("[data-#{type}-origin-slot-id]") + origin_slot_id = overlaySlot.data("#{type}-origin-slot-id") + origin_slot = $("[data-slot-id=#{origin_slot_id}]") + if origin_slot[0]? + origin_slot else - target_slot + console.log "couldn't find origin with slot id #{origin_slot_id}" reloadSlot: (url) -> $slot = $(this) if $slot.length > 1 $slot.each -> @@ -102,9 +117,11 @@ if mode == "overlay" @addOverlay(el, $slotter) else if el.hasClass("_modal-slot") or mode == "modal" el.showAsModal($slotter) else + slot_id = @data("slot-id") + el.attr("data-slot-id", slot_id) if slot_id @replaceWith el el.triggerSlotReady($slotter) triggerSlotReady: (slotter) ->