Code Explanation Request
Open in chat • 8 posts (analysis)
• Page 1 of 1
-

Mercury - Storyteller
I believe we have code that explains how to use the icon rendering outside of the wiki / forum. I specifically am interested in rendering a combination of the specialised and resource icons for the corporate zones and I believe we have library code for this, but I'm unable to figure out how it works. I can write it on my own, but since we already have it, if you could explain what I have to import and what functions I have to call to render for example "200 (:crystals+corp)" into the proper 200 with specialised crystals icon, it'd be much easier ^_^
The following goes into the header of your html:
The first two lines import the two relevant source files, the third line ensures that the fwurg-lib libraries know how to build urls that point to the correct icons.
Now you can call fwurg.icons.draw("(:whatever)") and it will spit out the necessary HTML. Note that you can only feed it icons, any rubbish around the icons will choke the method. Therefore, the following snippet is very useful: fwurg.icons.render("This message is about 200
"). The fwurg.icons.render method will try to replace all substrings starting with (: and ending in ) by their icons; if an icon is unknown, the empty string will be used.
(The render method exploits a very nice feature in javascript: javascript's replace function accepts regular expressions as the search string, and a function as the replacement string.)
- Code: Select all
<script language="javascript" src="/fwurg-lib/fwurg.js"></script>
<script language="javascript" src="/fwurg-lib/fwurg.icons.js"></script>
<script type="application/javascript">fwurg.url=function(r){return "/fwurg-lib/"+r;};</script>
The first two lines import the two relevant source files, the third line ensures that the fwurg-lib libraries know how to build urls that point to the correct icons.
Now you can call fwurg.icons.draw("(:whatever)") and it will spit out the necessary HTML. Note that you can only feed it icons, any rubbish around the icons will choke the method. Therefore, the following snippet is very useful: fwurg.icons.render("This message is about 200
"). The fwurg.icons.render method will try to replace all substrings starting with (: and ending in ) by their icons; if an icon is unknown, the empty string will be used.(The render method exploits a very nice feature in javascript: javascript's replace function accepts regular expressions as the search string, and a function as the replacement string.)
-

Mercury - Storyteller
Excellent, this works perfectly, thank you very much! I knew there was working code, I just wasn't able to figure it out, but now it works very well.
Am I correct to presume I need to do :dot1: replacements by hand? It is not an issue since there's nothing complicated about that, but if it is already featured, then doing so myself would be unnecessary.
Am I correct to presume I need to do :dot1: replacements by hand? It is not an issue since there's nothing complicated about that, but if it is already featured, then doing so myself would be unnecessary.
There is not :dot1: code as of yet. So go for it by hand for now. (I suggest looking at the fwurg.icons.render method for inspiration -- you basically want the same...)
-

Mercury - Storyteller
Note to future code editors. The following include is also recommended for the best results. It contains the CSS to properly render the icons.
- Code: Select all
<link type="text/css" rel="stylesheet" href="/fwurg-lib/include.tax-css.php" />
-

Mercury - Storyteller
Thanks for the clarification. I used this:
The replace all function is handwritten to replace all entries. Its very convenient and probably someone else did it better but mine works on O(n) so for n < 100 it really doesn't matter.
Note: :dot1: is the only case that applies for me - all higher dots aren't relevant. If they are, its better to use a proper method, but I'm lazy atm.
- Code: Select all
str = replaceAll(str, ":dot1:", "<big>●</big>");
The replace all function is handwritten to replace all entries. Its very convenient and probably someone else did it better but mine works on O(n) so for n < 100 it really doesn't matter.
Note: :dot1: is the only case that applies for me - all higher dots aren't relevant. If they are, its better to use a proper method, but I'm lazy atm.
Nooooooooooooooooooooooooo! That's not how it works, you lazy peasant!
That includes all css for the tax tool -- which might change without due notice.
You want to use this:
No custom code required: str = str.replace(/:dot1:/g, "<big>●</big>"); as long as you want to replace a constant... And this is MUCH more efficient than your find/replace loop.
Mercury wrote:Note to future code editors. The following include is also recommended for the best results. It contains the CSS to properly render the icons.
- Code: Select all
<link type="text/css" rel="stylesheet" href="/fwurg-lib/include.tax-css.php" />
That includes all css for the tax tool -- which might change without due notice.
You want to use this:
- Code: Select all
<link type="text/css" rel="stylesheet" href="/fwurg-lib/fwurg.icons.css" />
Mercury wrote:Thanks for the clarification. I used this:
- Code: Select all
str = replaceAll(str, ":dot1:", "<big>●</big>");
The replace all function is handwritten to replace all entries. Its very convenient and probably someone else did it better but mine works on O(n) so for n < 100 it really doesn't matter.
Note: :dot1: is the only case that applies for me - all higher dots aren't relevant. If they are, its better to use a proper method, but I'm lazy atm.
No custom code required: str = str.replace(/:dot1:/g, "<big>●</big>"); as long as you want to replace a constant... And this is MUCH more efficient than your find/replace loop.
-

Mercury - Storyteller
Fixed and fixed!
8 posts (analysis)
• Page 1 of 1
