2012-10-18 17:27:27 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/macros/view/viewers/transclude.js
|
|
|
|
type: application/javascript
|
2012-10-23 15:40:22 +00:00
|
|
|
module-type: fieldviewer
|
2012-10-18 17:27:27 +00:00
|
|
|
|
|
|
|
A viewer that transcludes the tiddler whose title is specified in the viewed field
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
2012-10-28 18:18:05 +00:00
|
|
|
var TranscludeViewer = function(viewMacro,tiddler,field,value) {
|
|
|
|
this.viewMacro = viewMacro;
|
|
|
|
this.tiddler = tiddler;
|
|
|
|
this.field = field;
|
|
|
|
this.value = value;
|
|
|
|
};
|
|
|
|
|
|
|
|
TranscludeViewer.prototype.render = function() {
|
|
|
|
if(this.tiddler && this.viewMacro.params.field && (this.viewMacro.params.field in this.tiddler.fields)) {
|
|
|
|
var children = this.viewMacro.wiki.parseTiddler(this.tiddler.fields[this.viewMacro.params.field]).tree,
|
2012-10-18 17:59:57 +00:00
|
|
|
childrenClone = [],t;
|
2012-10-18 17:27:27 +00:00
|
|
|
for(t=0; t<children.length; t++) {
|
|
|
|
childrenClone.push(children[t].clone());
|
|
|
|
}
|
|
|
|
for(t=0; t<childrenClone.length; t++) {
|
2012-10-28 18:18:05 +00:00
|
|
|
childrenClone[t].execute(this.viewMacro.parents,this.viewMacro.tiddlerTitle);
|
2012-10-18 17:27:27 +00:00
|
|
|
}
|
2012-10-28 18:18:05 +00:00
|
|
|
return $tw.Tree.Element(this.viewMacro.isBlock ? "div" : "span",{},childrenClone);
|
2012-10-18 17:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-28 18:18:05 +00:00
|
|
|
exports["transclude"] = TranscludeViewer;
|
2012-10-18 17:27:27 +00:00
|
|
|
|
|
|
|
})();
|