CodeIgniter Google Javascript Library Helper

A pretty useless helper actually, but included in CI core can make a big difference.

http://code.google.com/apis/ajaxlibs/documentation/index.html for more info.

Usage:

Put it in the system/helpers/ directory under the CI root

In controller file simply:
$this->load->helper('googlejs');
In view:
<?=load_gjs("jquery", "1.2.6", true);?> [library]/[version]/<compressed/uncompressed>

The output will be like this:
<script language="Javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>

by humancoder 1 year, 4 months ago and tagged with: codeigniter helper php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 4.3.2 or newer
 *
 * @package		CodeIgniter
 * @author		ExpressionEngine Dev Team
 * @copyright		Copyright (c) 2006, EllisLab, Inc.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * CodeIgniter Google Javascript Library Helper
 *
 * @package		CodeIgniter
 * @subpackage		Helpers
 * @category		Helpers
 * @author		Alexandru Plugaru
 * @link		http://hiresasha.net/
 * @link		http://code.google.com/apis/ajaxlibs/documentation/index.html
 */

// ------------------------------------------------------------------------

/**
 * Load Javascript
 *
 * Generates a script tag for js library loading.  First param is the library.
 * Second param is the version of the library and third is the compressed/uncompressed flag.
 *
 * @access	public
 * @param	string
 * @param	integer
 * @param	bool
 * @return	string
 */	
if ( ! function_exists('load_gjs'))
{
	function load_gjs($library, $version, $compressed = true){
		
		switch (strtolower($library)){
			case "jquery": 
				$c_url = "jquery.min";
				$u_url = "jquery";
			break;
			case "prototype":
				$c_url = "prototype";
				$u_url = $c_url;
			break;
			case "scriptaculous": 
				$c_url = "scriptaculous";
				$u_url = $c_url;
			break;
			case "mootools":
				$c_url = "mootools-yui-compressed";
				$u_url = "mootools"; 
			break;
			case "dojo":
				$c_url = "dojo.xd";
				$u_url = "dojo.xd.js.uncompressed";
			break;
		}
		return '<script language="Javascript" type="text/javascript" src="' . 'http://ajax.googleapis.com/ajax/libs/' . $library . '/' . $version . '/' . ($compressed?$c_url:$u_url) . '.js"></script>';
	}
}


/* End of file googlejs_helper.php */
/* Location: ./system/helpers/googlejs_helper.php */
?>

Currently 0 comments

To post a comment, you must login.