Skip to content

Instantly share code, notes, and snippets.

@lonalore
Last active June 14, 2017 12:28
Show Gist options
  • Save lonalore/a7c1d5aee0e7821dba03cb8ab5dfdefa to your computer and use it in GitHub Desktop.
Save lonalore/a7c1d5aee0e7821dba03cb8ab5dfdefa to your computer and use it in GitHub Desktop.

Using Newer Versions of jQuery in e107

You will often need a newer version of jQuery to use a certain jQuery plugin. There are two ways to achieve this.

Method 1: Using theme_library.php addon file in your theme folder

<?php

/**
 * @file
 * Provides information about external libraries.
 */


/**
 * Class theme_library.
 */
class theme_library
{

	/**
	 * Provides information about external libraries.
	 */
	function config()
	{
		return array();
	}

	/**
	 * Alters library information before detection and caching takes place.
	 */
	function config_alter(&$libraries)
	{
		// Override CDN library path. Make sure, CDN path is correct.
		$libraries['cdn.jquery']['path'] = '3.1.1';
		
		// Override local library path. Make sure, you have downloaded the files
		// to 'e107_web/lib/jquery/3.1.1' folder with the same folder structure
		// than 'e107_web/lib/jquery/2.2.4'.
		$libraries['jquery']['path'] = '3.1.1';
	}

}

Method 2: Using e_library.php addon file in your plugin folder

<?php

/**
 * @file
 * Provides information about external libraries.
 */


/**
 * Class PLUGIN_NAME_library.
 */
class PLUGIN_NAME_library
{

	/**
	 * Provides information about external libraries.
	 */
	function config()
	{
		return array();
	}

	/**
	 * Alters library information before detection and caching takes place.
	 */
	function config_alter(&$libraries)
	{
		// Override CDN library path. Make sure, CDN path is correct.
		$libraries['cdn.jquery']['path'] = '3.1.1';
		
		// Override local library path. Make sure, you have downloaded the files
		// to 'e107_web/lib/jquery/3.1.1' folder with the same folder structure
		// than 'e107_web/lib/jquery/2.2.4'.
		$libraries['jquery']['path'] = '3.1.1';
	}

}

Finally, visit Admin UI / Preferences / Libraries page, and check your jQuery libraries.

@CaMer0n
Copy link

CaMer0n commented Jan 28, 2017

What would happen if 2 different plugins request conflicting libraries? eg. 2 different versions of jquery

@lonalore
Copy link
Author

One overrides the other. But only one version of jQuery will be loaded.

@rica-carv
Copy link

And how use the cdn files (using its cdn web path) from e_library.php or theme_library.php?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment