How to Properly Test if jQuery is Loaded

I saw many people claiming you can test for the existence of jQuery like this:

1
2
3
4
5
if (jQuery) {
	// jQuery exists, put code here
} else {
	// jQuery not loaded, put code here
}

This is incorrect. It will work fine if jQuery is loaded, but if it's not loaded, javascript will throw an error and the code to execute if jQuery is not loaded will probably not be processed. The modification to fix this is simple:

1
2
3
4
5
if (window.jQuery) {
	// jQuery exists, put code here
} else {
	// jQuery not loaded, put code here
}
[ad]

How to Hide Android WebView Highlight Border (or change it’s color)

Here's one that had me at a loss for a long time that I just figured out. You can easily remove the highlight border (the border that comes up when an element is focused) or change it's color in a WebView with CSS! The WebKit-specific property "-webkit-tap-highlight-color" is what you're looking for.

The following line will disable it on a page completely:

1
2
3
* {
	-webkit-tap-highlight-color: rgba(0, 0, 0, 0);	
}

rgba() is just like rgb(), but it takes a 4th parameter for opacity. It's my belief that this would probably work for iPhone WebView's as well, since both Chrome and Safari are based off of WebKit.

[ad]

PHP RSS Parser – RSS Reader Class for PHP

Just had to create a quick RSS parser for PHP and thought I'd post my solution. The implementation and class follows.

<?php
$rss = new RSSReader('http://news.google.com/?output=rss');
while ($rss -> hasNext())
	print_r($rss -> next());
?>
[ad]
<?php
class RSSReader {
	var $xml = null;
	var $pos = 0;
	var $count = 0;
 
	function __construct($feed_url) {
		$this -> load_url($feed_url);
	}
 
	function load_url($feed_url) {
		$this -> load_string(file_get_contents($feed_url));
	}
 
	function load_string($feed_string) {
		$this -> xml = simplexml_load_string(str_replace('content:encoded', 'content_encoded', $feed_string));
		$this -> pos = 0;
		$this -> count = count($this -> xml -> channel -> item);
	}
 
	function get_title() {
		return $this -> xml -> channel -> title;
	}
 
	function get_link() {
		return $this -> xml -> channel -> link;
	}
 
	function get_pubdate() {
		return $this -> xml -> channel -> pubdate;
	}
 
	function hasNext() {
		return $this -> count > $this -> pos;
	}
 
	function next() {
		$obj = $this -> xml -> channel -> item[$this -> pos++];
		return array(
			'title' => (string) $obj -> title,
			'link' => (string) $obj -> link,
			'description' => (string) $obj -> description,
			'content' => (string) $obj -> content_encoded,
			'pubDate' => strtotime($obj -> pubDate),
		);
	}
}
?>

Chrome Extensions: History Button, Extensions Button, Downloads Button

I just created some very simple extensions for Chrome shortly after I taught myself how to create extensions.

As I said, they're VERY simple, but I find them useful, so I figured it wouldn't hurt to share them.

Each extension is a simple lightweight extension that adds a shortcut button to your browser for quick access to your history, extensions, or downloads. It either opens a new tab, or switches to the respective tab if you already have it open in a tab you're not using.

You could nearly accomplish the same thing if you made a bookmark, but this assures you won't open multiple tabs and I like to keep some things separate from the bookmarks bar.

Chrome Extensions Button

Chrome History Button

Chrome Downloads Button

[ad]