Archive

Posts Tagged ‘jquery’

Fetch Google Pages Indexed Using PHP and AJAX

April 1st, 2010 No comments

Here’s a quick and dirty solution I threw together to fetch how many pages of a site google has index. I needed this for one of my control panels, so my work group could track this and other metrics on the fly.

gpindex.php

<?php
	// Some arbitrary access code so not everyone can access it. Not "real" security :)
	if($_GET['accessCode']!="some_password") { echo "Access Denied"; exit; }
 
	$site = $_GET['site'];
	$gurl = "http://www.google.com/search?q=site:";
 
	$curl_handle=curl_init();
	curl_setopt($curl_handle,CURLOPT_URL,$gurl.$site);
	curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
	curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
	$buffer = curl_exec($curl_handle);
	curl_close($curl_handle);
 
	preg_match_all("#Results(.*)of about <b>(.*)</b> from <b>$site</b>#",$buffer,$matches,0);
	echo $matches[2][0];
?>

And here’s the Ajax via jQuery that is used to fetch the information:

<script type="text/javascript" src="js/patch/jquery.min.js"></script>
<script type="text/javascript">
   $(document).ready(function(){
      $.ajax({
         url:"http://www.example.com/path/to/gpindex.php?accessCode=some_password&site=example.com",
         success:function(d){$("#googleIndexed").html(d+" Pages");}
      });
   });
</script>
<p style="font-size:11px;">Indexed on Google</p>
<p style="font-size:11px; font-weight:bold;" id="googleIndexed">( Fetching Data )</p>
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon
Categories: PHP Tags: , ,

IE6 / IE7 jQuery Fix: Anchor Image Clickable Area

September 25th, 2009 3 comments

IE6 and IE7 both experience a problem in which images inside of block elements inside of anchors lose their click ability. Here’s an example:

<a href="rss-icon.png">
	<span style="display:block; width:100px; height:100px;">
		<img src="someImage.png" />
	</span>
</a>

Every area of the link remains click-able except for the surface consumed by someImage.png. (Note, this problem will not show in IE8, or FF)

Here’s a very small jQuery plugin I wrote to fix this particular issue.

(function($){
	$.fn.fixClick = function() {
		return this.each(function(){
			$(this)
				.css({cursor:'pointer'})
				.click(function(){
					window.location.href = $(this).attr('href'); 
				});
		});
	}
})(jQuery);

Simply select your target element(s) and use this plugin to make the entire anchor click-able again. Here’s an example:

$(document).ready(function(){
   $('a').fixClick();
});
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon
Categories: JavaScript, Web Design Tags: , , , ,

Alternating Styles in jQuery (Plug-In)

July 16th, 2009 No comments

This is a little script that I wrote, that lets you easily alternate the style of repeating class elements, or w/e elements you want to select. This is particularly useful for lists, and the like.

function($){
$.fn.styleAlternation = function(aClass, bClass) {
    var i = 0;
    return this.each(function() {
        if (++i % 2 != 0 && aClass!='') {
            $(this).addClass(aClass);
        } else if(bClass!='') {
            $(this).addClass(bClass);
        }
    });
}(jQuery);

The usage is very simple. Here’s the JavaScript:

$("#awesomeTable tr").styleAlternation("cssClass1","cssClass2");

From there, all you need to do is create your CSS. Example:

.cssClass1 { background: #000; color: #444; }
.cssClass2 { background: #999; color: #333; }

Here’s a screenshot:
Alternation Demo

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon
Categories: JavaScript Tags: ,

AJAX Calendar Loader Using jQuery

July 15th, 2009 No comments

My good pal Austin needed help turning his static calendar into one that could change the month, using AJAX. The calendar itself was written in PHP. Here is the quick and easy solution I came up with for him, using jQuery:

$(document).ready(function() {
 
   // Create Date Object
   var jsDateObject = new Date();
 
   // Create Calendar Object ( Holds all your variables, etc )
   var jsCalendar = {};
       jsCalendar.currentMonth = jsDateObject.getMonth();
 
   // Controls the NEXT button
   $("#jsCalendarNext").click(function() {
      // Update Active Month
      jsCalendar.currentMonth++;
         if(jsCalendar.currentMonth>12) { jsCalendar.currentMonth=1; }
 
      // Get New Calendar
      ajaxUpdateCalendar();
   });
 
   // Controls the PREV button
   $("#jsCalendarPrev").click(function() {
      // Update Active Month
      jsCalendar.currentMonth--;
         if(jsCalendar.currentMonth<1) { jsCalendar.currentMonth=12; }
 
      // Get New Calendar
      ajaxUpdateCalendar();
   });
 
   // Use AJAX to update the Calendar
   function ajaxUpdateCalendar() {
      $.post(
         "phpCalendarLoader.php",
         { calendarMonth: jsCalendar.currentMonth },
         function(data) {
            $("#jsCalendarContainer").html(data);
         },
         "html"
      );
   }
 
});

From here, all Austin had to do was set his $month variable to $_POST['calendarMonth'];.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon
Categories: JavaScript Tags: ,