[Docs] Filter by Base Item in runewords page

Discuss Median XL!
User avatar
axtroz
Dark Huntress
14 | 5
Hi,

While I love the new docs, I am struggling to find exactly what I'm looking for in the runewords page due to the way the search field works (it looks for the search term anywhere in multiple fields).
For instance, if I want to see the RWs for any weapon, ordered by level requirements, I'll type "weapons" in the search bar, then sort by level.
However, the result includes Paladin Blunt Weapons, Barbarian Weapons and even Amazon Bows (RW "Colliding Worlds" gives +(1 to 6) to Elfin Weapons ).

I propose an additional drop-down menu next to the search bar that allows filtering based on the Base Item. The use of the filter will limit the results the Search bar is going through, thus allowing more specific searches.

I wrote a small script that implements this proposal in a very non-intrusive way: It generates the drop-down dynamically, so no modifications to the website code are required, other than the inclusion of the script itself. The only requirement is it to load the script after the DataTables plugin.

Tested with Chrome 61.0.3163.100, Firefox 55.0.3 and the Edgiest browser out there.

The full source is below, it's quite verbose to make it easier to read.

Code: Select all

;;(function(){

   var RunewordsTable = $("#DataTables_Table_0").DataTable();
   var BaseItems = RunewordsTable.column(4).data().sort().unique().filter(function(value){ return !value.match("except"); });
   var DataTablesFilterContainer = $("#DataTables_Table_0_filter");
   var Label = $("<label/>").html("Filter by base item:&nbsp;").prependTo(DataTablesFilterContainer);
   var BaseItemFilter = $("<select/>").css({margin: "0 2px 2px 0"}).appendTo(Label).on('change', filterBaseItem);

   function filterBaseItem(event) {
      // The RunewordsTable works due to it being defined in the scope of the closure
      var BaseItem;
      if (!event.target.value) {
         BaseItem = "";
      }
      else {
         // The regex matches only the beginning due to a but with the runewords with exclusions
         BaseItem = "^BI".replace(/BI/, event.target.value);
      };

      RunewordsTable.column(4).search(BaseItem, true, false).draw();
   };
   // Default to any base item (show all)
   $("<option/>").val("").html("-- Show all --").prependTo(BaseItemFilter);

   // Create a selector for each base item in the drop-down
   $.each(BaseItems, function(index, BaseItem){
      BaseItemFilter.append($("<option/>").val(BaseItem).html(BaseItem));
   });

})();


Here's the same, but minified to save up a few KBs if you'd like:

Code: Select all

!function(){function a(a){var l;l=a.target.value?"^BI".replace(/BI/,a.target.value):"",t.column(e).search(l,!0,!1).draw()}var e=4,t=$("#DataTables_Table_0").DataTable(),l=t.column(e).data().sort().unique().filter(function(a){return!a.match("except")}),n=$("#DataTables_Table_0_filter"),o=$("<label/>").html("Filter by base item:&nbsp;").prependTo(n),r=$("<select/>").css({margin:"0 2px 2px 0"}).appendTo(o).on("change",a);$("<option/>").val("").html("-- Show all --").prependTo(r),$.each(l,function(a,e){r.append($("<option/>").val(e).html(e))})}();


[EDIT] Here's a video showing it in action (the dropdown is invisible due to video recording addon):
Edited by axtroz 6 years.
User avatar
Zennith
Grubber
310 | 30
Common Popularity Badge
Has a thread with over 10.000 views
Common Love Badge
Earned over 20 cookies
Great Supporter Badge
Donated 5 times
Edit: Hurr durr. For some reason, I felt like the page was forcing me to view a limited number. However, when using the search function it is weird to type weapons and it seems organized weirdly.
User avatar
Crash
Madawc
6799 | 327
Great Posting Badge
Posted over 2.500 messages
Legendary Popularity Badge
Has a thread with over 250.000 views
Great Love Badge
Earned over 100 cookies
Great Supporter Badge
Donated 5 times
Common Showcase Badge
Median XL Broadcaster
Common Guide Badge
Created a complete character guide
Common Contribution Badge
Has collaborated to our forums, realms or mod
Common Auction Badge
Won 50 auctions
Zennith wrote:Edit: Hurr durr. For some reason, I felt like the page was forcing me to view a limited number. However, when using the search function it is weird to type weapons and it seems organized weirdly.


Just don't click a number in the dropdown menu and it won't limit your search results to a number.
User avatar
axtroz
Dark Huntress
14 | 5
So the only two comments are regarding something completely different...
Do you like/dislike the idea?
Sliwka
Pit Knight
109 | 1
Common Popularity Badge
Has a thread with over 10.000 views
I like the idea
User avatar
RequiemLux
Sand Maggot
1125 | 288
Common Posting Badge
Posted over 1.000 messages
Legendary Popularity Badge
Has a thread with over 250.000 views
Great Love Badge
Earned over 100 cookies
Legendary Contribution Badge
Median XL Team Member
I like the idea too, more options to the users are always welcomed
User avatar
JetJet
Abomination
149 | 0
Not saying I don't like the new RW filter but int he old one I could just ctrl+f to find the RW I'm looking for.
User avatar
Crash
Madawc
6799 | 327
Great Posting Badge
Posted over 2.500 messages
Legendary Popularity Badge
Has a thread with over 250.000 views
Great Love Badge
Earned over 100 cookies
Great Supporter Badge
Donated 5 times
Common Showcase Badge
Median XL Broadcaster
Common Guide Badge
Created a complete character guide
Common Contribution Badge
Has collaborated to our forums, realms or mod
Common Auction Badge
Won 50 auctions
JetJet wrote:Not saying I don't like the new RW filter but int he old one I could just ctrl+f to find the RW I'm looking for.


You can.
User avatar
shnurr214
Ice Clan
597 | 47
Common Popularity Badge
Has a thread with over 10.000 views
Common Love Badge
Earned over 20 cookies
Common Supporter Badge
Donated 1 time
Common Contribution Badge
Has collaborated to our forums, realms or mod
nice mock up.

I dont really think this is necessary however seems to be an addional ui layer that isnt really needed but hey thats just my opinion. I still think its cool that community members have the passion to mock stuff up like this.