vendor/assets/javascripts/emerson/sink.js in emerson-0.0.4 vs vendor/assets/javascripts/emerson/sink.js in emerson-0.0.5

- old
+ new

@@ -27,19 +27,45 @@ // ### $.fn.sink // // $(target).sink() // + // Given "replacement" content and for each "sink" (existing content): + // + // 1. fire "sink:before" with the sink as the target. + // 2. replace the sink with a "prepared" replacement. + // 3. fire "sink:after" with the replacement as the target. $.fn.sink = function() { _.each(this, function(e) { var elem = $(e); var key = elem.data('sink'); if(key) { - elem.replaceAll('[data-sink="' + key + '"]', 'body'); - elem.trigger('sink:after'); + $('[data-sink="' + key + '"]').each(function() { + $(this) + .trigger('sink:before') + .replaceWith(prepare(elem)); + }); + + $('[data-sink="' + key + '"]').trigger('sink:after'); } }); return this; }; + + + // Internal Implementation + // -------------------------------------------------------------------------- + + // ### prepare + // Clone the replacement source and, if Emerson.view is defined, apply that. + function prepare(source) { + var result = source.clone(); + + if(Emerson.view) { + result.view(); + } + + return result; + } })(Emerson);