mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-01 03:39:09 +00:00
Update render.js
This commit is contained in:
parent
e44d6f4d7b
commit
0a7c57c860
@ -50,14 +50,46 @@ exports.startup = function() {
|
||||
$tw.styleElement = document.createElement("style");
|
||||
$tw.styleElement.innerHTML = $tw.styleWidgetNode.assignedStyles;
|
||||
document.head.insertBefore($tw.styleElement,document.head.firstChild);
|
||||
$tw.wiki.addEventListener("change",$tw.perf.report("styleRefresh",function(changes) {
|
||||
// Prepare refresh mechanism
|
||||
var deferredChanges = Object.create(null),
|
||||
timerId,
|
||||
throttledRefreshFn = function(changes,callback,mainCondition,styleCondition) {
|
||||
// Check if only tiddlers that are throttled have changed
|
||||
var onlyThrottledTiddlersHaveChanged = true;
|
||||
for(var title in changes) {
|
||||
var tiddler = $tw.wiki.getTiddler(title);
|
||||
if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") || (mainCondition && tiddler.hasField("throttle.refresh.main")) || (styleCondition && tiddler.hasField("throttle.refresh.style"))))) {
|
||||
onlyThrottledTiddlersHaveChanged = false;
|
||||
}
|
||||
}
|
||||
// Defer the change if only drafts have changed
|
||||
if(timerId) {
|
||||
clearTimeout(timerId);
|
||||
}
|
||||
timerId = null;
|
||||
if(onlyThrottledTiddlersHaveChanged) {
|
||||
var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10);
|
||||
if(isNaN(timeout)) {
|
||||
timeout = THROTTLE_REFRESH_TIMEOUT;
|
||||
}
|
||||
timerId = setTimeout(throttledRefresh,timeout);
|
||||
$tw.utils.extend(deferredChanges,changes);
|
||||
} else {
|
||||
$tw.utils.extend(deferredChanges,changes);
|
||||
callback(changes);
|
||||
}
|
||||
};
|
||||
function styleRefresh(changes) {
|
||||
if($tw.styleWidgetNode.refresh(changes,$tw.styleContainer,null)) {
|
||||
var newStyles = $tw.styleContainer.textContent;
|
||||
if(newStyles !== $tw.styleWidgetNode.assignedStyles) {
|
||||
$tw.styleWidgetNode.assignedStyles = newStyles;
|
||||
$tw.styleElement.innerHTML = $tw.styleWidgetNode.assignedStyles;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$tw.wiki.addEventListener("change",$tw.perf.report("styleRefresh",function(changes) {
|
||||
throttledRefreshFn(changes,styleRefresh,false,true);
|
||||
}));
|
||||
// Display the $:/core/ui/PageTemplate tiddler to kick off the display
|
||||
$tw.perf.report("mainRender",function() {
|
||||
@ -75,9 +107,6 @@ exports.startup = function() {
|
||||
removeItem.parentNode.removeChild(removeItem);
|
||||
}
|
||||
});
|
||||
// Prepare refresh mechanism
|
||||
var deferredChanges = Object.create(null),
|
||||
timerId;
|
||||
function refresh() {
|
||||
// Process the refresh
|
||||
$tw.hooks.invokeHook("th-page-refreshing");
|
||||
@ -89,30 +118,7 @@ exports.startup = function() {
|
||||
|
||||
// Add the change event handler
|
||||
$tw.wiki.addEventListener("change",$tw.perf.report("mainRefresh",function(changes) {
|
||||
// Check if only tiddlers that are throttled have changed
|
||||
var onlyThrottledTiddlersHaveChanged = true;
|
||||
for(var title in changes) {
|
||||
var tiddler = $tw.wiki.getTiddler(title);
|
||||
if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh")))) {
|
||||
onlyThrottledTiddlersHaveChanged = false;
|
||||
}
|
||||
}
|
||||
// Defer the change if only drafts have changed
|
||||
if(timerId) {
|
||||
clearTimeout(timerId);
|
||||
}
|
||||
timerId = null;
|
||||
if(onlyThrottledTiddlersHaveChanged) {
|
||||
var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10);
|
||||
if(isNaN(timeout)) {
|
||||
timeout = THROTTLE_REFRESH_TIMEOUT;
|
||||
}
|
||||
timerId = setTimeout(throttledRefresh,timeout);
|
||||
$tw.utils.extend(deferredChanges,changes);
|
||||
} else {
|
||||
$tw.utils.extend(deferredChanges,changes);
|
||||
refresh();
|
||||
}
|
||||
throttledRefreshFn(changes,refresh,true,false);
|
||||
}));
|
||||
// Fix up the link between the root widget and the page container
|
||||
$tw.rootWidget.domNodes = [$tw.pageContainer];
|
||||
|
Loading…
Reference in New Issue
Block a user