Hi blueprint tags seem to be kinda broken with Firefox.
In his thread I started only the very first bp button actually copies its string to the clipboard.
The other buttons don't copy their content to clipboard even though their code seems identical apart from the string.
blueprint button script problem
Re: blueprint button script problem
Well, that's funny. They copied the code from the wiki, but didn't do it correctly
To the person who will be tasked to fix this: Use a class, not an ID! Element IDs should be unique within the webpage, otherwise you run into situations like this where a browser can only ever get the first element with that ID. If you have to use an ID for some reason, make it unique by appending a number or something similar.
To the person who will be tasked to fix this: Use a class, not an ID! Element IDs should be unique within the webpage, otherwise you run into situations like this where a browser can only ever get the first element with that ID. If you have to use an ID for some reason, make it unique by appending a number or something similar.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Re: blueprint button script problem
Should be fixed now
Re: blueprint button script problem
Math.random is not guaranteed to be uniqueKlonan wrote:Should be fixed now
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Re: blueprint button script problem
Here is an idea on how to script it so that you never have problems. The current solution seems very hacky to me.
Current implementation (guess, since I cant see the direct code):
From what I can find in the phpbb docs, you have no limitations on what you put into the html field for the custom bbcodes, so you can just put the function directly on the button:
This way, you dont rely on browser quirks and random values not being the same.
Current implementation (guess, since I cant see the direct code):
Code: Select all
[bp]{TEXT}[/bp]
<button style="background-color:rgb(19, 93, 144); color:rgb(221, 221, 221); line-height:46px; width:180px; cursor:pointer;"><img src="https://wiki.factorio.com/images/Blueprint.png" style="vertical-align:middle;"> Copy blueprint string</button>
<script>
var button = document.getElementById("BPbutton");
button.id = button.id + '_' + Math.random().toString(36).substr(2, 9);
button.addEventListener("click", function (event) {
var copyTarget = document.createElement("input");
copyTarget.setAttribute("value", {TEXT});
document.body.appendChild(copyTarget);
copyTarget.select();
document.execCommand("copy");
document.body.removeChild(copyTarget);
});
</script>
Code: Select all
[bp]{TEXT}[/bp]
<button style="background-color:rgb(19, 93, 144); color:rgb(221, 221, 221); line-height:46px; width:180px; cursor:pointer;" onclick="var copyTarget = document.createElement('input'); copyTarget.setAttribute('value', {TEXT}); document.body.appendChild(copyTarget); copyTarget.select(); document.execCommand('copy'); document.body.removeChild(copyTarget);"><img src="https://wiki.factorio.com/images/Blueprint.png" style="vertical-align:middle;"> Copy blueprint string</button>
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Re: blueprint button script problem
Math.random seems to fix it for my browser, no idea if Safari or some other browser will behave properly though.
My Mods: mods.factorio.com
Re: blueprint button script problem
Math.random() generates a 64-bit number, which is big enough that a birthday collision is unlikely on this forum.
Of course it is not a good habit to use random ids, it does not scale well past a few hundred blueprints per page.
Of course it is not a good habit to use random ids, it does not scale well past a few hundred blueprints per page.