marko/widgets/taglib/include-tag.js
2016-11-30 20:46:31 -07:00

23 lines
791 B
JavaScript

var isBrowser = typeof window !== 'undefined';
var normalInclude = require('../../taglibs/core/include-tag');
var markoWidgets = require('../');
module.exports = function include(input, out) {
var target = input._target;
if (typeof target === 'string') {
out.text(target);
} else if (target) {
normalInclude(input, out);
} else if (isBrowser) {
var widgetId = input._widgetId;
// Thereis no body content so let's see if we should reuse
// the existing body content in the DOM
var existingEl = document.getElementById(widgetId);
if (existingEl) {
var widgetsContext = markoWidgets.getWidgetsContext(out);
widgetsContext.addPreservedDOMNode(existingEl, true /* body only */);
}
}
};