kopia lustrzana https://github.com/miklobit/TiddlyWiki5
				
				
				
			Fix templates for lazy loading
							rodzic
							
								
									a7f247b28c
								
							
						
					
					
						commit
						e2ce4e11e8
					
				|  | @ -20,19 +20,14 @@ exports.name = "jsontiddlers"; | |||
| 
 | ||||
| exports.params = [ | ||||
| 	{name: "filter"}, | ||||
| 	{name: "spaces"}, | ||||
| 	{name: "escapeUnsafeScriptCharacters"} | ||||
| 	{name: "spaces"} | ||||
| ]; | ||||
| 
 | ||||
| /* | ||||
| Run the macro | ||||
| */ | ||||
| exports.run = function(filter,spaces,escapeUnsafeScriptCharacters) { | ||||
| 	var json = this.wiki.getTiddlersAsJson(filter,{ | ||||
| 		spaces: $tw.utils.parseInt(spaces), | ||||
| 		escapeUnsafeScriptCharacters: escapeUnsafeScriptCharacters === "yes" | ||||
| 	}); | ||||
| 	return json; | ||||
| exports.run = function(filter,spaces) { | ||||
| 	return this.wiki.getTiddlersAsJson(filter,$tw.utils.parseInt(spaces)); | ||||
| }; | ||||
| 
 | ||||
| })(); | ||||
|  | @ -0,0 +1,79 @@ | |||
| /*\ | ||||
| title: $:/core/modules/widgets/jsontiddler.js | ||||
| type: application/javascript | ||||
| module-type: widget | ||||
| 
 | ||||
| Render a tiddler as JSON text | ||||
| 
 | ||||
| \*/ | ||||
| (function(){ | ||||
| 
 | ||||
| /*jslint node: true, browser: true */ | ||||
| /*global $tw: false */ | ||||
| "use strict"; | ||||
| 
 | ||||
| var Widget = require("$:/core/modules/widgets/widget.js").widget; | ||||
| 
 | ||||
| var JSONTiddlerWidget = function(parseTreeNode,options) { | ||||
|     this.initialise(parseTreeNode,options); | ||||
| }; | ||||
| 
 | ||||
| /* | ||||
| Inherit from the base widget class | ||||
| */ | ||||
| JSONTiddlerWidget.prototype = new Widget(); | ||||
| 
 | ||||
| /* | ||||
| Render this widget into the DOM | ||||
| */ | ||||
| JSONTiddlerWidget.prototype.render = function(parent,nextSibling) { | ||||
|     var self = this; | ||||
|     this.parentDomNode = parent; | ||||
|     this.computeAttributes(); | ||||
|     this.execute(); | ||||
|     var fields = {}; | ||||
|     if(this.attTiddler) { | ||||
|         var tiddler = this.wiki.getTiddler(this.attTiddler); | ||||
|         if(tiddler) { | ||||
|             fields = tiddler.getFieldStrings({exclude: this.attExclude.split(" ")}); | ||||
|         } | ||||
|     } | ||||
| 	$tw.utils.each(this.attributes,function(attribute,name) { | ||||
| 		if(name.charAt(0) === "$") { | ||||
|             fields[name.slice(1)] = attribute; | ||||
| 		} | ||||
| 	}); | ||||
|     var json = JSON.stringify(fields); | ||||
|     if(this.attEscapeUnsafeScriptChars) { | ||||
| 		json = json.replace(/</g,"\\u003C"); | ||||
|     } | ||||
|     var textNode = this.document.createTextNode(json); | ||||
|     parent.insertBefore(textNode,nextSibling); | ||||
|     this.domNodes.push(textNode); | ||||
| }; | ||||
| 
 | ||||
| /* | ||||
| Compute the internal state of the widget | ||||
| */ | ||||
| JSONTiddlerWidget.prototype.execute = function() { | ||||
|     this.attTiddler = this.getAttribute("tiddler"); | ||||
|     this.attExclude = this.getAttribute("exclude",""); | ||||
|     this.attEscapeUnsafeScriptChars = this.getAttribute("escapeUnsafeScriptChars","no") === "yes"; | ||||
| }; | ||||
| 
 | ||||
| /* | ||||
| Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering | ||||
| */ | ||||
| JSONTiddlerWidget.prototype.refresh = function(changedTiddlers) { | ||||
|     var changedAttributes = this.computeAttributes(); | ||||
|     if($tw.utils.count(changedAttributes) > 0 || (this.attTiddler && changedTiddlers[this.attTiddler])) { | ||||
|         this.refreshSelf(); | ||||
|         return true; | ||||
|     } else { | ||||
|         return false; | ||||
|     } | ||||
| }; | ||||
| 
 | ||||
| exports.jsontiddler = JSONTiddlerWidget; | ||||
| 
 | ||||
| })(); | ||||
|  | @ -700,40 +700,21 @@ exports.getTiddlerAsJson = function(title) { | |||
| 	} | ||||
| }; | ||||
| 
 | ||||
| /* | ||||
| Options: | ||||
| spaces: number of spaces. The special value -1 results in a line break in between each tiddler | ||||
| escapeUnsafeScriptCharacters: true to force escaping of characters that cannot be embedded in HTML | ||||
| */ | ||||
| exports.getTiddlersAsJson = function(filter,options) { | ||||
| 	options = options || {}; | ||||
| 	if(typeof options === "string") { | ||||
| 		options = {spaces: options}; | ||||
| 	} | ||||
| 	var titles = this.filterTiddlers(filter), | ||||
| 		spaces = (options.spaces === undefined) ? $tw.config.preferences.jsonSpaces : options.spaces, | ||||
| 		data = [], | ||||
| 		t; | ||||
| 	for(t=0;t<titles.length; t++) { | ||||
| 		var tiddler = this.getTiddler(titles[t]); | ||||
| exports.getTiddlersAsJson = function(filter,spaces) { | ||||
|     var tiddlers = this.filterTiddlers(filter), | ||||
|         spaces = (spaces === undefined) ? $tw.config.preferences.jsonSpaces : spaces, | ||||
|         data = []; | ||||
|     for(var t=0;t<tiddlers.length; t++) { | ||||
|         var tiddler = this.getTiddler(tiddlers[t]); | ||||
|         if(tiddler) { | ||||
| 			data.push(tiddler.getFieldStrings()); | ||||
|             var fields = new Object(); | ||||
|             for(var field in tiddler.fields) { | ||||
|                 fields[field] = tiddler.getFieldString(field); | ||||
|             } | ||||
|             data.push(fields); | ||||
|         } | ||||
|     } | ||||
| 	var json; | ||||
| 	if(spaces === -1) { | ||||
| 		var jsonLines = []; | ||||
| 		for(t=0;t<data.length; t++) { | ||||
| 			jsonLines.push(JSON.stringify(data[t])); | ||||
| 		} | ||||
| 		json = "[\n" + jsonLines.join(",\n") + "\n]"; | ||||
| 	} else { | ||||
| 		json = JSON.stringify(data,null,spaces); | ||||
| 	} | ||||
| 	if(options.escapeUnsafeScriptCharacters) { | ||||
| 		json = json.replace(/</g,"\\u003C"); | ||||
| 	} | ||||
| 	return json; | ||||
|     return JSON.stringify(data,null,spaces); | ||||
| }; | ||||
| 
 | ||||
| /* | ||||
|  |  | |||
|  | @ -0,0 +1,4 @@ | |||
| title: $:/core/templates/html-json-skinny-tiddler | ||||
| 
 | ||||
| <$list filter="[<numTiddlers>compare:number:gteq[1]] ~[<counter>!match[1]]">`,`<$text text=<<newline>>/></$list> | ||||
| <$jsontiddler tiddler=<<currentTiddler>> exclude="text" escapeUnsafeScriptChars="yes"/> | ||||
|  | @ -0,0 +1,4 @@ | |||
| title: $:/core/templates/html-json-tiddler | ||||
| 
 | ||||
| <$list filter="[<counter>!match[1]]">`,`<$text text=<<newline>>/></$list> | ||||
| <$jsontiddler tiddler=<<currentTiddler>> escapeUnsafeScriptChars="yes"/> | ||||
|  | @ -5,9 +5,16 @@ title: $:/core/templates/store.area.template.html | |||
| <$list filter="[[$:/isEncrypted]get[text]else[no]match[no]]"> | ||||
|     <$list filter="[[storeAreaFormat]is[variable]getvariable[]else[json]match[json]]"> | ||||
|         <!-- New-style JSON store area, with an old-style store area for compatibility with v5.1.x tooling --> | ||||
|         `<script class="tiddlywiki-tiddler-store" type="application/json">` | ||||
|             <$macrocall $name="jsontiddlers" filter=<<saveTiddlerFilter>> spaces="-1" escapeUnsafeScriptCharacters="yes" $output="text/raw"/> | ||||
|         `</script>` | ||||
|         `<script class="tiddlywiki-tiddler-store" type="application/json">[` | ||||
|             <$vars newline={{{ [charcode[10]] }}}> | ||||
|                 <$text text=<<newline>>/> | ||||
|                 <$list filter=<<saveTiddlerFilter>> counter="counter" template="$:/core/templates/html-json-tiddler"/> | ||||
|                 <$vars numTiddlers={{{ [subfilter<saveTiddlerFilter>count[]] }}}> | ||||
|                     <$list filter={{{ [<skinnySaveTiddlerFilter>] }}} counter="counter" template="$:/core/templates/html-json-skinny-tiddler"/> | ||||
|                 </$vars> | ||||
|                 <$text text=<<newline>>/> | ||||
|             </$vars> | ||||
|         `]</script>` | ||||
|         `<div id="storeArea" style="display:none;">` | ||||
|         `</div>` | ||||
|     </$list> | ||||
|  |  | |||
|  | @ -0,0 +1,4 @@ | |||
| title: $:/core/templates/html-json-skinny-tiddler | ||||
| 
 | ||||
| <$list filter="[<numTiddlers>compare:number:gteq[1]] ~[<counter>!match[1]]">`,`<$text text=<<newline>>/></$list> | ||||
| <$jsontiddler tiddler=<<currentTiddler>> exclude="text" escapeUnsafeScriptChars="yes" $revision=<<changecount>> $bag="default" $_is_skinny=""/> | ||||
|  | @ -0,0 +1,4 @@ | |||
| title: $:/core/templates/html-json-tiddler | ||||
| 
 | ||||
| <$list filter="[<counter>!match[1]]">`,`<$text text=<<newline>>/></$list> | ||||
| <$jsontiddler tiddler=<<currentTiddler>> escapeUnsafeScriptChars="yes" $revision=<<changecount>> $bag="default">/> | ||||
		Ładowanie…
	
		Reference in New Issue
	
	 jeremy@jermolene.com
						jeremy@jermolene.com