-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Colour handling improvements #8702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 161 commits
fb9c0d6
93d1c05
467a1a4
a23ee16
e1e73d2
1e5c69e
4af573a
96b85ed
d372729
b5a22e3
fc36941
151f61a
4445111
4f2754d
bc0fde6
85fa913
a8fb071
81b7bb4
ff5c846
23eccd1
c607440
348f717
c3ce9ca
a4d9303
250e57c
1be89a2
f889157
4e2f2be
b54d56e
297ae7e
38d5daa
bad9517
46da161
1db8cf7
ad1b0fd
21cd3b8
7de5f40
c2ee072
3faf9ba
8b59b61
809465b
cfabc92
b2d0c22
32ac671
b0828cc
3507b0f
84bef54
76f2dec
aa69c3a
cd5bbcd
9efcad9
fc695e7
6a66c49
6fe16bc
5a6eea7
b1fcb18
1df0ac4
ae1d9f5
c1e36a1
2640406
3c44532
2685fa7
2eee3bf
2558dc0
6a06df7
b90b449
c02c825
5d1cf25
6b39d6a
d1ce548
a429306
2cbd108
bd4b3e4
28167ad
2b0c634
69363bf
2edcf0f
55d9e92
c75f50e
3614236
62fb916
9681b0d
0baf395
28c1e77
9588b7f
407e58f
8c619fd
0dfde06
7513e44
3ea7cd3
0fd5b04
8957424
d2bbc56
317e124
0c8aad4
efcd239
546e438
effeed7
c1fd82f
139b61f
22cf3b2
a6a91d4
a366d62
431149d
6970ac2
a053f03
c6bb2b5
c7f9dbf
30a7d61
0ee2f28
2e5a988
a5c4d90
38865a4
998d5c8
6e4d7aa
f9e4dd8
4d06ecd
796c33b
0d9ab2e
961b26a
4fe90a6
4c21664
bfea62b
1f4f164
eba73ee
7c49382
e87aaff
4665bab
7df9878
d8dfc10
7da70ec
d2204ae
92b7819
71a144f
28935a5
611adad
83c6223
067a1a2
422b092
09f8ab9
49969a2
377856c
0037813
d7df7ed
8b05b72
2028420
059e439
93f9544
75ba085
8467fa3
624cf95
250ee90
3001696
ee977de
d42e3d3
4c95ae5
5e27462
5897b82
e86eb28
54382d6
e9d87fb
5335ebf
a4c84d7
dcf0f44
7f2a47f
77c99b4
96d2475
96ef5c8
38457a4
9749045
f9721b0
39488f1
da41483
4b83e89
ae33a45
5b0c923
b0dc46c
fd85842
3353d0e
8a18f92
502598b
3cab157
c707b9a
3254544
9641e6a
6dc8338
a8c4437
93388bc
fd709af
bb4d57e
d35e34b
e98aed6
dcaff6a
8cc94d8
87f797b
c7511fc
421ecff
829bb61
5b96929
2f8d53d
9b56734
ef49828
eb8f69d
5b0af90
a8e056c
ae7d6da
a45a872
3f654bc
59d23da
35b0108
15736bc
a752503
fe708ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| /*\ | ||
| title: $:/core/modules/background-actions.js | ||
| type: application/javascript | ||
| module-type: global | ||
|
|
||
| Class to dispatch actions when filters change | ||
|
|
||
| \*/ | ||
| (function(){ | ||
|
|
||
| /*jslint node: true, browser: true */ | ||
| /*global $tw: false */ | ||
| "use strict"; | ||
|
|
||
| function BackgroundActionDispatcher(filterTracker,wiki) { | ||
| var self = this; | ||
| this.filterTracker = filterTracker; | ||
| this.wiki = wiki; | ||
| this.nextTrackedFilterId = 1; | ||
| this.trackedFilters = Object.create(null); // Hashmap by id | ||
| // Track the filter for the background actions | ||
| this.filterTracker.track({ | ||
| filterString: "[all[tiddlers+shadows]tag[$:/tags/BackgroundAction]!is[draft]]", | ||
| fnEnter: function fnEnter(title) { | ||
| return self.trackFilter(title); | ||
| }, | ||
| fnLeave: function fnLeave(title,enterValue) { | ||
| self.untrackFilter(enterValue); | ||
| }, | ||
| fnChange: function fnChange(title,enterValue) { | ||
| self.untrackFilter(enterValue); | ||
| return self.trackFilter(title); | ||
| }, | ||
| fnProcess: function fnProcess(changes) { | ||
| self.process(changes); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| BackgroundActionDispatcher.prototype.trackFilter = function(title) { | ||
| var tiddler = this.wiki.getTiddler(title), | ||
| id = this.nextTrackedFilterId++, | ||
|
||
| tracker = new BackgroundActionTracker({ | ||
| wiki: this.wiki, | ||
| title: title, | ||
| trackFilter: tiddler.fields["track-filter"], | ||
| actions: tiddler.fields.text | ||
| }); | ||
| this.trackedFilters[id] = tracker; | ||
| return id; | ||
| }; | ||
|
|
||
| BackgroundActionDispatcher.prototype.untrackFilter = function(enterValue) { | ||
pmario marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| var tracker = this.trackedFilters[enterValue]; | ||
| if(tracker) { | ||
| tracker.destroy(); | ||
| } | ||
| delete this.trackedFilters[enterValue]; | ||
| }; | ||
|
|
||
| BackgroundActionDispatcher.prototype.process = function(changes) { | ||
| for(var id in this.trackedFilters) { | ||
| this.trackedFilters[id].process(changes); | ||
| } | ||
| }; | ||
|
|
||
| /* | ||
| Represents an individual tracked filter. Options include: | ||
| wiki: wiki to use | ||
| title: title of the tiddler being tracked | ||
| trackFilter: filter string to track changes | ||
| actions: actions to be executed when the filter changes | ||
| */ | ||
| function BackgroundActionTracker(options) { | ||
| var self = this; | ||
| this.wiki = options.wiki; | ||
| this.title = options.title; | ||
| this.trackFilter = options.trackFilter; | ||
| this.actions = options.actions; | ||
| this.filterTracker = new $tw.FilterTracker(this.wiki); | ||
| this.hasChanged = false; | ||
| this.trackerID = this.filterTracker.track({ | ||
| filterString: this.trackFilter, | ||
| fnEnter: function(title) { | ||
| self.hasChanged = true; | ||
| }, | ||
| fnLeave: function(title,enterValue) { | ||
| self.hasChanged = true; | ||
| }, | ||
| fnProcess: function(changes) { | ||
| if(self.hasChanged) { | ||
| self.hasChanged = false; | ||
| console.log("Processing background action",self.title); | ||
| var tiddler = self.wiki.getTiddler(self.title), | ||
| doActions = true; | ||
| if(tiddler && tiddler.fields.platforms) { | ||
| doActions = false; | ||
| var platforms = $tw.utils.parseStringArray(tiddler.fields.platforms); | ||
| if(($tw.browser && platforms.indexOf("browser") !== -1) || ($tw.node && platforms.indexOf("node") !== -1)) { | ||
| doActions = true; | ||
| } | ||
| } | ||
| if(doActions) { | ||
| self.wiki.invokeActionString( | ||
| self.actions, | ||
| null, | ||
| { | ||
| currentTiddler: self.title | ||
| },{ | ||
| parentWidget: $tw.rootWidget | ||
| } | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| BackgroundActionTracker.prototype.process = function(changes) { | ||
| this.filterTracker.handleChangeEvent(changes); | ||
| }; | ||
|
|
||
| BackgroundActionTracker.prototype.destroy = function() { | ||
| this.filterTracker.untrack(this.trackerID); | ||
| }; | ||
|
|
||
| exports.BackgroundActionDispatcher = BackgroundActionDispatcher; | ||
|
|
||
| })(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /*\ | ||
| title: $:/core/modules/filter-tracker.js | ||
| type: application/javascript | ||
| module-type: global | ||
|
|
||
| Class to track the results of a filter string | ||
|
|
||
| \*/ | ||
| (function(){ | ||
|
|
||
| /*jslint node: true, browser: true */ | ||
| /*global $tw: false */ | ||
| "use strict"; | ||
|
|
||
| function FilterTracker(wiki) { | ||
| this.wiki = wiki; | ||
| this.trackers = []; | ||
| this.nextTrackerId = 1; | ||
| } | ||
|
|
||
| FilterTracker.prototype.handleChangeEvent = function(changes) { | ||
| this.processTrackers(); | ||
| this.processChanges(changes); | ||
| }; | ||
|
|
||
| /* | ||
| Add a tracker to the filter tracker. Returns null if any of the parameters are invalid, or a tracker id if the tracker was added successfully. Options include: | ||
| filterString: the filter string to track | ||
| fnEnter: function to call when a title enters the filter results. Called even if the tiddler does not actually exist. Called as (title), and should return a truthy value that is stored in the tracker as the "enterValue" | ||
| fnLeave: function to call when a title leaves the filter results. Called as (title,enterValue) | ||
| fnChange: function to call when a tiddler changes in the filter results. Only called for filter results that identify a tiddler or shadow tiddler. Called as (title,enterValue), and may optionally return a replacement enterValue | ||
| fnProcess: function to call each time the tracker is processed, after any enter, leave or change functions are called. Called as (changes) | ||
| */ | ||
| FilterTracker.prototype.track = function(options) { | ||
| // Add the tracker details | ||
| var tracker = { | ||
| id: this.nextTrackerId++, | ||
| filterString: options.filterString, | ||
| fnEnter: options.fnEnter, | ||
| fnLeave: options.fnLeave, | ||
| fnChange: options.fnChange, | ||
| fnProcess: options.fnProcess, | ||
| previousResults: [], // Results from the previous time the tracker was processed | ||
| resultValues: {} // Map by title to the value returned by fnEnter | ||
| }; | ||
| this.trackers.push(tracker); | ||
| // Process the tracker | ||
| this.processTracker(this.trackers.length - 1); | ||
| return tracker.id; | ||
| }; | ||
|
|
||
| FilterTracker.prototype.untrack = function(id) { | ||
| for(var t=0; t<this.trackers.length; t++) { | ||
| if(this.trackers[t].id === id) { | ||
| this.trackers.splice(t,1); | ||
| break; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| FilterTracker.prototype.processTrackers = function() { | ||
| for(var t=0; t<this.trackers.length; t++) { | ||
| this.processTracker(t); | ||
| } | ||
| }; | ||
|
|
||
| FilterTracker.prototype.processTracker = function(index) { | ||
| var tracker = this.trackers[index]; | ||
| var results = []; | ||
| // Evaluate the filter and remove duplicate results | ||
| $tw.utils.each(this.wiki.filterTiddlers(tracker.filterString),function(title) { | ||
| $tw.utils.pushTop(results,title); | ||
| }); | ||
| // Process the newly entered results | ||
| $tw.utils.each(results,function(title) { | ||
| if(tracker.previousResults.indexOf(title) === -1 && !tracker.resultValues[title] && tracker.fnEnter) { | ||
| tracker.resultValues[title] = tracker.fnEnter(title) || true; | ||
| } | ||
| }); | ||
| // Process the results that have just left | ||
| $tw.utils.each(tracker.previousResults,function(title) { | ||
| if(results.indexOf(title) === -1 && tracker.resultValues[title] && tracker.fnLeave) { | ||
| tracker.fnLeave(title,tracker.resultValues[title]); | ||
| delete tracker.resultValues[title]; | ||
| } | ||
| }); | ||
| // Update the previous results | ||
| tracker.previousResults = results; | ||
| }; | ||
|
|
||
| FilterTracker.prototype.processChanges = function(changes) { | ||
| for(var t=0; t<this.trackers.length; t++) { | ||
| var tracker = this.trackers[t]; | ||
| $tw.utils.each(changes,function(change,title) { | ||
| if(title && tracker.previousResults.indexOf(title) !== -1 && tracker.fnChange) { | ||
| // Call the change function and if it doesn't return a value then keep the old value | ||
| tracker.resultValues[title] = tracker.fnChange(title,tracker.resultValues[title]) || tracker.resultValues[title]; | ||
| } | ||
| }); | ||
| if(tracker.fnProcess) { | ||
| tracker.fnProcess(changes); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| exports.FilterTracker = FilterTracker; | ||
|
|
||
| })(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /*\ | ||
| title: $:/core/modules/filterrunprefixes/apply.js | ||
| type: application/javascript | ||
| module-type: filterrunprefix | ||
|
|
||
| Filter run prefix to make input titles available as variables when evaluating the filter run | ||
|
|
||
| \*/ | ||
| (function(){ | ||
|
|
||
| /*jslint node: true, browser: true */ | ||
| /*global $tw: false */ | ||
| "use strict"; | ||
|
|
||
| exports.apply = function(operationSubFunction) { | ||
| return function(results,source,widget) { | ||
| source = widget.wiki.makeTiddlerIterator([]); | ||
| var variables = {}, | ||
| counter = 1; | ||
| results.each(function(title) { | ||
| variables["$" + counter] = title; | ||
| counter++; | ||
| }); | ||
| results.clear(); | ||
| results.pushTop(operationSubFunction(source,widget.makeFakeWidgetWithVariables(variables))); | ||
| }; | ||
| }; | ||
|
|
||
| })(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /*\ | ||
| title: $:/core/modules/filters/changecount.js | ||
| type: application/javascript | ||
| module-type: filteroperator | ||
|
|
||
| Filter operator for retrieving the changecount for each title in the list. | ||
|
|
||
| \*/ | ||
| (function(){ | ||
|
|
||
| /*jslint node: true, browser: true */ | ||
| /*global $tw: false */ | ||
| "use strict"; | ||
|
|
||
| /* | ||
| Export our filter function | ||
| */ | ||
| exports.changecount = function(source,operator,options) { | ||
| var results = []; | ||
| source(function(tiddler,title) { | ||
| results.push(options.wiki.getChangeCount(title) + ""); | ||
| }); | ||
| return results; | ||
| }; | ||
|
|
||
| })(); |
Uh oh!
There was an error while loading. Please reload this page.