It's been asked for and here it is! I sent an email to the 'Powers That Be' asking if they'd like me to Not post about adding code to your post and got no reply. As such I will assume they aren't against it. If a MOD is reading this and IS against it, PLEASE kill this thread ;).
Some people have asked how I'm able to modify the text and pictures on postings through the 'Reply' and 'Submit a combo' text boxes. It's actually quite simple and requires just a little knowledge of how code/logic works. I've been using HTML, Javascript, and sometimes even a little CSS to make these work. This tutorial will go over how to change the Popout picture with a Reply to a combo. I'll explain each part below.
One of the first things you should know is how the current webpage is coded, on your browser click View>Source (Right click on the page and select 'View Page Source' in Firefox). This will bring up a windows with the Source code for the page, this may seem like a lot of information, but it is actually pretty simple to disect once you look into it. One of the things you will notice when looking at the source code for a combo is where the page defines the area that is the card (you can use ctrl+f to search for the cardname) is there's a couple parts to the cardposting, we'll use for example <a href="card.php?id=19164" class="combo_link" target="_blank" onMouseOver="ShowCard('Card1',1)" onMouseOut="ShowCard('Card1',0)">Swamp</a><div id="Card1"><img src="images/cards/ze/swamp.jpg"></div>
The HTML:
This code comes in two parts, you can identify the parts by seeing where the objects were created and closed. All of the text inbetween the '<' and '>' is run as HTML code by your browser. Some objects require that they be closed after you've created them, this allows you to put text inbetween the opening and closing of the object that will be part of that object. The best example is the <a href="{webpage URL}">{link}</a> object. If you use this, any text in the area I called {link} would show up as a link to click and go to another site where the area marked as {webpage URL} would be that webpage. As a proof <a href="http://www.mtgcombos.com">Best Combo Site EVER!!!</a> would show up as Best Combo Site EVER!!!. If we look at our example we can see that the first part is a link like this but has a lot of other things defined in it, we'll get to those later. For now you can see how clicking the text 'Swamp' would bring you to another webpage!
The second part is listed as a <div> object. This object is used to easily reference the information inside of it and is almost always formatted <div> {HTML code} </div> . In HTML the object is created with the <div> and ended with the </div> just like <a></a>. With what we're looking at on our example you will see <div id="Card1"><img src="images/cards/ze/swamp.jpg"></div>. The code in the middle is a standard definition of an image. It begins with ‘img’ and lists a URL source for the picture (src). The img object doesn’t need to be closed in the same way as the <div></div> and <a></a> objects so you don’t need a </img> at the end of it.
The Javascript
Now that we know what each of these two parts are in HTML, how can you make it do something Entirely different? You just need a scripting language, in this case we’re using Javascript. Sometimes you have an HTML statement within an object, this defines a property of the object. Common ones include href, src, and id (in the first two they aren’t available to all objects). Looking at some of the objects you can figure out what they do, href defines a hyperlink reference, class defines the class of the object (not important to this tutorial), onMouseOver and onMouseOut say what to do when the object is moused over and out respectively, id defines the object id for reference later, and src tells the source for the object. All of these properties are formatted Property=”text” but can have Javascript in the place of the text! You could, if you want, have it say onMouseOver=”Alert(‘Your Moused Over’);”. You see in that example that I used a different quote sign for the text within the alert. This is because the browser will execute anything within any matching set of quotes as the text, after that it will assume that is part of more code. If we were to order it as onMouseOver=”Alert(“You Moused Over”);” it would think onMouseOver equaled Alert( and then process the next text as a continuation of the object definition. It may seem complex, just remember to be careful nesting your quotes, never break them up. The common way to nest the quotes is to put the double quotes on the outside and single quotes on the inside ( “ ‘text‘ “ ) though both should work ( ‘ “text“ ‘ too). If you find yourself in a situation where you need a third set of quotes you can use the javascript command ". The browser will read that as a double quote when it executes that code so you should be fine ( “ ‘ "text" ‘ “).
Another thing you may notice is that all of the Javascript code seems to be ending with a semicolon ‘;’. This is there to tell the browser that this is the end of that line of code and to prepare to execute another line. If your code isn’t working correctly be sure to check for missing semicolons, it’s cause too many headaches in my code to count ;).
As an example of the javascript you’ll see above that the example we’re working off of has an onMouseOver event set to run the code ShowCard(‘Card1’,1). This is a function that was defined earlier in the page and is just being called with the text Card1 and the number 1 as variables for it to reference. We don’t need to know the details of exactly what this does, it’s just a good tool for reference. Looking at the <div> object we se that it has an id set as “Card1”. If we need to, we can reference this with the javascript command
document.getElementById
which in this case we’ll format as
document.getElementById(‘Card1’)
where Card1 is the id of the element you getting. This returns the whole object <div id="Card1"><img src="images/cards/ze/swamp.jpg"></div> . If we want to reference anything within this object we can just put a period after the line we typed and use that extension. In this case we can use the .innerHTML command to call upon the text within the <div>…</div> command. Using our example again
document.getElementById(‘Card1’).innerHTML
would return ‘<img src="images/cards/ze/swamp.jpg">‘. If we wanted to change this text all we would have to do is put an ‘=’ sign after it and put the text we want to it be. This would come out to be something like
document.getElementById(“Card1”).innerHTML=”<img src=’images/cards/ze/island.jpg’>”;
Notice a couple things in this, the use of nested quotes and the ending in a semicolon that we mentioned. This javascript will modify the code of the webpage as it is executed and write the text in where you told it! But how do you actually go about executing it? Like I said before, you need to have it executed within the text of an HTML command. The best results I’ve had has been with the ‘onload’ property which can be used within an img object. I usually create a picture at the beginning of the post with
<img src=”images/clear.gif” onload=”script”>
If you put the text we made up a minute ago in here you’ll get
<img src=”images/clear.gif” onload=”document.getElementById(“Card1”).innerHTML=”<img src=’images/cards/ze/island.jpg’>”;”>
See any problem with this? The nesting on the quotes is off, using the instructions I gave on nesting quotes you can format it to look like this
<img src=”images/clear.gif” onload=”document.getElementById(‘Card1’).innerHTML=’<img src="images/cards/ze/island.jpg">’;”>
This text will change the popout picture for the card to be an island instead of a swamp. You can reference pictures from outside of the current website if you wish, this lets you load the picture from a site that have a more up to date database of cards. This is how that works
<img src=”images/clear.gif” onload=”document.getElementById(‘Card1’).innerHTML=’<img src=" http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=206072&type=card">’;”>
Whew that was a lot, you’ve learned some very basic HTML and Javascript and how to use it to modify a page on your post, but how to you implement it in your post, you need to be sure you click on the HTML button at the top of the textbox. Be sure you DON’T do this until you’ve finished typing the text for your post we’ll do one last small example for proof. Type your text
This is my Post.
Isn’t it Great!!!
Click on the HTML button up top and you’ll see the text change to this:
<P>This is my Post.</P><P>Isn’t it Great</P>
Add your html and javascript at the start of this text and you’ll get something like this:
<img src=”images/clear.gif” onload=”document.getElementById(‘Card1’).innerHTML=’<img src=" http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=206072&type=card">’;”> <P>This is my Post.</P><P>Isn’t it Great</P>
It looks like a lot of confusing text, but it’s all stuff we’ve gone over and easily understood if you think of each part individually. This text should be fully functional on a comment post, but there are other issues with making these changes with an initial combo posting. This tutorial will instruct you how to modify your original post or add a comment to modify the popout. I will use another thread to go over more advanced topics like changing the text on the link using the document.links command and how to implement logic commands like the For and If statements. If you have any questions about this all, just comment below. Later I will create a popout object for this thread for you to play with in the comments ;) |