2014-07-20 17:07:30 +00:00
/ * \
title : $ : / c o r e / m o d u l e s / s t a r t u p / i n f o . j s
type : application / javascript
module - type : startup
Initialise $ : / i n f o t i d d l e r s v i a $ : / t e m p / i n f o - p l u g i n p s e u d o - p l u g i n
\ * /
( function ( ) {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict" ;
// Export name and synchronous status
exports . name = "info" ;
exports . before = [ "startup" ] ;
exports . after = [ "load-modules" ] ;
exports . synchronous = true ;
2019-09-16 11:15:39 +00:00
var TITLE _INFO _PLUGIN = "$:/temp/info-plugin" ;
2014-07-20 17:07:30 +00:00
exports . startup = function ( ) {
2020-11-24 19:01:33 +00:00
// Function to bake the info plugin with new tiddlers
var updateInfoPlugin = function ( tiddlerFieldsArray ) {
// Get the existing tiddlers
var json = $tw . wiki . getTiddlerData ( TITLE _INFO _PLUGIN , { tiddlers : { } } ) ;
// Add the new ones
$tw . utils . each ( tiddlerFieldsArray , function ( fields ) {
if ( fields && fields . title ) {
json . tiddlers [ fields . title ] = fields ;
}
} ) ;
// Bake the info tiddlers into a plugin. We use the non-standard plugin-type "info" because ordinary plugins are only registered asynchronously after being loaded dynamically
var fields = {
title : TITLE _INFO _PLUGIN ,
type : "application/json" ,
"plugin-type" : "info" ,
text : JSON . stringify ( json , null , $tw . config . preferences . jsonSpaces )
} ;
$tw . wiki . addTiddler ( new $tw . Tiddler ( fields ) ) ;
} ;
2014-07-20 17:07:30 +00:00
// Collect up the info tiddlers
2020-11-24 19:01:33 +00:00
var tiddlerFieldsArray = [ ] ;
// Give each info module a chance to provide as many info tiddlers as they want as an array, and give them a callback for dynamically updating them
2014-07-20 17:07:30 +00:00
$tw . modules . forEachModuleOfType ( "info" , function ( title , moduleExports ) {
if ( moduleExports && moduleExports . getInfoTiddlerFields ) {
2020-11-24 19:01:33 +00:00
Array . prototype . push . apply ( tiddlerFieldsArray , moduleExports . getInfoTiddlerFields ( updateInfoPlugin ) ) ;
2014-07-20 17:07:30 +00:00
}
} ) ;
2020-11-24 19:01:33 +00:00
updateInfoPlugin ( tiddlerFieldsArray ) ;
var changes = $tw . wiki . readPluginInfo ( [ TITLE _INFO _PLUGIN ] ) ;
$tw . wiki . registerPluginTiddlers ( "info" , [ TITLE _INFO _PLUGIN ] ) ;
2014-07-20 17:07:30 +00:00
$tw . wiki . unpackPluginTiddlers ( ) ;
} ;
} ) ( ) ;