diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-10-20 15:10:44 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-10-20 15:10:44 -0400 |
commit | 28fdb9e4e7f5419947226171bf6d7efa273802c5 (patch) | |
tree | 26231b40f1e6c338e00f420b1856ae298dceea7c /src/SMAPI.Web/wwwroot/Content/js | |
parent | f09befe24047de8187276c722557b6f0fddd6e35 (diff) | |
download | SMAPI-28fdb9e4e7f5419947226171bf6d7efa273802c5.tar.gz SMAPI-28fdb9e4e7f5419947226171bf6d7efa273802c5.tar.bz2 SMAPI-28fdb9e4e7f5419947226171bf6d7efa273802c5.zip |
add mod compatibility page (#597)
Diffstat (limited to 'src/SMAPI.Web/wwwroot/Content/js')
-rw-r--r-- | src/SMAPI.Web/wwwroot/Content/js/mods.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/SMAPI.Web/wwwroot/Content/js/mods.js b/src/SMAPI.Web/wwwroot/Content/js/mods.js new file mode 100644 index 00000000..1b15b622 --- /dev/null +++ b/src/SMAPI.Web/wwwroot/Content/js/mods.js @@ -0,0 +1,56 @@ +/* globals $ */ + +var smapi = smapi || {}; +var app; +smapi.modList = function (mods) { + // init data + var data = { mods: mods, search: "" }; + for (var i = 0; i < data.mods.length; i++) { + var mod = mods[i]; + + // set initial visibility + mod.Visible = true; + + // concatenate searchable text + mod.SearchableText = [mod.Name, mod.AlternateNames, mod.Author, mod.AlternateAuthors, mod.Compatibility.Summary, mod.BrokeIn]; + if (mod.Compatibility.UnofficialVersion) + mod.SearchableText.push(mod.Compatibility.UnofficialVersion); + if (mod.BetaCompatibility) { + mod.SearchableText.push(mod.BetaCompatibility.Summary); + if (mod.BetaCompatibility.UnofficialVersion) + mod.SearchableText.push(mod.BetaCompatibility.UnofficialVersion); + } + for (var p = 0; p < mod.ModPages; p++) + mod.SearchableField.push(mod.ModPages[p].Text); + mod.SearchableText = mod.SearchableText.join(" ").toLowerCase(); + } + + // init app + app = new Vue({ + el: "#app", + data: data, + methods: { + /** + * Update the visibility of all mods based on the current search text. + */ + applySearch: function () { + // get search terms + var words = data.search.toLowerCase().split(" "); + + // make sure all words match + for (var i = 0; i < data.mods.length; i++) { + var mod = data.mods[i]; + var match = true; + for (var w = 0; w < words.length; w++) { + if (mod.SearchableText.indexOf(words[w]) === -1) { + match = false; + break; + } + } + + mod.Visible = match; + } + } + } + }); +}; |