Magic The Gathering Combos
Search Cards & Combos:

Home     Submit A Combo     Deck Builder     Forums     Picture Guess     Help

You are not logged in [click to login] - [Join For Free!]  





Forum Overview >> General Chat
Title: How to Modify a popout picture with the Reply button
Date Posted: Fri May/04/12 at 3:35pm

Squillis
Posts: 424
Joined: 20-Nov-08

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 &quot;.  The browser will read that as a double quote when it executes that code so you should be fine ( “ ‘ &quot;text&quot; ‘ “).

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=&quot;images/cards/ze/island.jpg&quot;>’;”>

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=&quot; http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=206072&type=card&quot;>’;”>

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=&quot; http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=206072&type=card&quot;>’;”> <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 ;)

Date Posted: Fri May/04/12 at 3:40pm

Squillis
Posts: 424
Joined: 20-Nov-08

I learned most of this at W3Schools.com, it's a Great place to learn all kinds of web-based coding for free


[Edited by Squillis on 4/May/12 at 3:40PM]
Date Posted: Sat May/05/12 at 8:54am

Boyachi
Posts: 1553
Joined: 02-Nov-11

This is the first page from this site that I've added to my favorite places.

That's saying something considering that one of the combos that I saw posted on here is the sole reason that I'm overhauling one of my decks this week.

I wish this post could be stickied to the top so that it wouldn't be lost in time later on.
Date Posted: Mon May/07/12 at 7:48am

Squillis
Posts: 424
Joined: 20-Nov-08

My coding isn't yet to the level as being able to modify where a post will show up on the message board.  I can only modify what's shown when the code in the post is executed.  If it's sticky'd it'd have to be done by the mods, though, I'm not even sure that ability is built into this forum.
Date Posted: Mon May/07/12 at 8:59am

Boyachi
Posts: 1553
Joined: 02-Nov-11

Hahaha, I was saying that TPTB should sticky it, to showcase your findings, not to make you do it. You've done enough and we are greatful for it!
Date Posted: Tue May/22/12 at 8:27am

Squillis
Posts: 424
Joined: 20-Nov-08

I've added a popout below, play with editing it to your heart's content!  The div id is Card0.

Craw Wurm


Date Posted: Tue May/22/12 at 9:04am

Turbine
Posts: 10194
Joined: 26-Oct-09

Mods? There ain't any mods here, boy.

Thanks for the post. It will be very useful.
Date Posted: Tue May/22/12 at 10:26am

Twogunkid
Posts: 2609
Joined: 22-Jan-10

Mods? We have unofficial hierarchy and one admin. Lets see digging up Sync's old mod thread.... That's Gericault Lin Sivvi and Me followed by Jester Turbine and the Captain.

I think Sync would be fine with it. If not I guess we will be graced by a rare appearance.


[Edited by Twogunkid on 22/May/12 at 10:27AM]
Date Posted: Tue May/22/12 at 11:04am

Turbine
Posts: 10194
Joined: 26-Oct-09

Could you modify the website to give people admin privileges? XD
Date Posted: Tue May/22/12 at 12:08pm

Squillis
Posts: 424
Joined: 20-Nov-08

Though I'm not that advanced, it wouldn't surprise me.  The level of access to the code means the person writing the code could not only modify the code on the current page but also the PHP code that creates what you see on the site.  This would give the coder access to not only potential admin priveliges but maybe even the pool of user logins.  Like I said, it could be Very dangerous if someone malicious who ACTUALLY KNEW WHAT THEY WERE DOING got on here.
Date Posted: Tue May/22/12 at 12:41pm

DyingJester
Posts: 1771
Joined: 16-Dec-08

Anyone else thinking a backup forum should be established, should anything happen to this one?
Date Posted: Tue May/22/12 at 1:48pm

Turbine
Posts: 10194
Joined: 26-Oct-09

We need to find a way to make this website more secure. If we can't contact Sync ourselves, is their anyway that we could modify the website to be more safe ourselves?
Date Posted: Thu May/31/12 at 9:00am

Squillis
Posts: 424
Joined: 20-Nov-08

Maybe, but that gets into dangerous territory that I'm not experienced or daring enough to venture into.  If I were to modify the code that generates the page or limits others posting abilities not only would I risk Serious damage to the site if I fail but it also could Easily be construed as vandalism or even some kind of Digital B&E (breaking and entering).  Like I said, I'm no hacker but would also love to see these holes fixed.

[Edited by Squillis on 31/May/12 at 9:01AM]
Date Posted: Fri Jun/01/12 at 9:25pm

Turbine
Posts: 10194
Joined: 26-Oct-09

It was a joke. . .but the fact that you responded seriously shows the vulnerability of the site.
Date Posted: Sat Jun/02/12 at 6:48am

shakii23
Posts: 5711
Joined: 08-Sep-09

i tried that once... but i based the code from the wizards.com website...



Forum Overview >> General Chat

©2006-2023 MTGCombos.com