DOM foolery
Since I’ve been making random DOM and JavaScript posts recently I thought I’d share a clever bog post I found cleverly called DOM-foolery. It describes a relatively simple way to make images in web pages have curved corners.
Since I’ve been making random DOM and JavaScript posts recently I thought I’d share a clever bog post I found cleverly called DOM-foolery. It describes a relatively simple way to make images in web pages have curved corners.
Something interesting occured to me recently. Evolution of the human species has been basically halted by healthcare. Since the weak no longer die before reproducing, the makeup of the genes of subsequent generations is random. The good news is the cure needs no effort as such. If we let the population grow until we no longer have enough food then people will start dying more. The people who manage to survive will pass on their genes and evolution will begin again. The only question remains is whether the survivors are the sort of people we want continuing the species. They will predominantly be the rich and although many rich people get that way by being smart or more productive somehow, some of them definitely don’t.
starvation, evolution, over population
That’s the name I’ve come up with for the game since it’s vaguley based on Cash Wars. Or at least will be. I’ve started adding descriptions to towns. There are a few issues still though, most notably the existence of multiple towns with the same name which I am eliminating (I’m only intending to have the largest 100 towns).
I decided on a whim to try PartyPoker.com (for free) and ended up having far more fun than I expected.
Unfortunately the minimum deposit to play for money is $50 which is far more than I’m willing to spend…
Here’s a demo of what may become a game: Cash City Wars.
There are various reasons for the title I won’t go into right now… Basically the game will involve you moving from city to city in some way (quite exactly what the mechanics of the game will be I don’t know yet). The cool thing is that it will use real geographic data. At the moment there is only data for the UK but depending on availability I could add the whole world.
Although they don’t like it, the town names are in fact clickable.
Part of the online game I’m now developing (which needs a name - I was thinking of “Cash City Wars”) requires some Javascript that alters the style of a DIV
and then puts it back as it was. Changing the style is easy. For example to make the text green:
// Some code to get the DIV object and store it in obj.
obj.style.color = "green";
Storing the old style information is a little difficult. I tried:
obj.oStyle = obj.style;
obj.style.color = "green";
But that didn’t work for two reasons: firstly objects are passed by reference so oStyle
always contained the same thing as style
. And secondly style
(when used for reading) only contains explicitly set properties. So if you set width
and left
you’d still have to work out right
yourself.
I found out there is another property you can use, getComputedStyle
. This has it’s own little quirks however. Firstly it isn’t an method of the object, but used more like a function and secondly it doesn’t seem to work in IE6.
Firefox (W3 DOM):
temp = document.defaultView.getComputedStyle(obj, "");
temp.getPropertyValue(prop);
IE6
obj.currentStyle[prop];
I personally think the IE way makes more sense in this case but we have to cope wtih both. One thing that is slightly awkward is that one is a function the other is an array. So to make a simple to use interface to the correct function, we can use Javascript’s ability to use functions as first class objects (which means you can assign them to variables):
if (document.defaultView) {
var cStyle = function(obj, prop) {
var temp = document.defaultView.getComputedStyle(obj, "");
return temp.getPropertyValue(prop);
}
} else if (document.body.currentStyle) {
var cStyle = function(obj, prop) {
return obj.currentStyle[prop];
}
}
You can now call cStyle
like a normal function to get the computed value of any style property of any object.
I found a site a while ago that was willing to pay for text links on your site. The wanted them not because they thought they’d get more direct traffic but because they’d get an increase in PageRank.
It’s quite a popular idea these days with a few sites offering text link brokering services. You pay them and they get several high PR sites to link to you. Doesn’t matter if the sites content don’t match, just that Google finds the link. I never had a site with a high enough PageRank until now to actually join. Now I do, I thought I’d give it a spin; I joined Text Link Brokers.
A quick search on Google revealed little information (lots of question on forums with no answers). There was one negative comment but it was apparently about one of the competitors instead that has a very similar name. Anyway a couple of days after signing up I was told I need to reduce the number of external links since they only allow 20 in total and want to be responsible for five of them (that’s why I now have a bit at the bottom of the page counting external links). After sorting that out they sent an email for the rates they are willing to pay. And they’re pretty good. Not marvelous but they don’t actually require people to click like Adsense ads do.
The one problem is I now have to wait for someone to actually buy links.
I spend a couple of days away from the internet and things happen!
Google now allow you to split a page into sections with the idea that Adsense ads are only targetted to the text in that section. A couple of comments is all you need: <! -- google_ad_section_start -->
<! -- google_ad_section_end -->
Apparently Google only take this as a suggestion but in some situations it could help. Of course sticking to one topic per page is better nearly all the time anyway.
Here’s a work in progress version of the online game based on real geography idea I had. Demo.
I was reading a tutorial on using PHP and GD with GIS data, that is how to draw maps with PHP using real life data. There has to be a cool way to make on online game out of this although I’m not sure what. I was thinking something along the lines of the old CashWars game…