X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Flibraries%2Flibraries.api.php;fp=web%2Fmodules%2Fcontrib%2Flibraries%2Flibraries.api.php;h=859e6023eb4529bcdb3731fefc7a44971744aabe;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/libraries/libraries.api.php b/web/modules/contrib/libraries/libraries.api.php new file mode 100644 index 000000000..859e6023e --- /dev/null +++ b/web/modules/contrib/libraries/libraries.api.php @@ -0,0 +1,609 @@ +1.3-beta2)' + * // Only load a version equal to or later than 1.3-beta3: + * 'example (>=1.3-beta3)', + * // Only load a version earlier than 1.5: + * 'example (<1.5)', + * // Only load a version equal to or earlier than 1.4: + * 'example (<=1.4)', + * // Combinations of the above are allowed as well: + * 'example (>=1.3-beta2, <1.5)', + * ); + * @endcode + * - variants: (optional) An associative array of available library variants. + * For example, the top-level 'files' property may refer to a default + * variant that is compressed. If the library also ships with a minified and + * uncompressed/source variant, those can be defined here. Each key should + * describe the variant type, e.g. 'minified' or 'source'. Each value is an + * associative array of top-level properties that are entirely overridden by + * the variant, most often just 'files'. Additionally, each variant can + * contain following properties: + * - variant callback: (optional) The name of a function that detects the + * variant and returns TRUE or FALSE, depending on whether the variant is + * available or not. The first argument is always $library, an array + * containing all library information as described here. The second + * argument is always a string containing the variant name. There are two + * ways to declare the variant callback's additional arguments, either as a + * single $options parameter or as multiple parameters, which correspond + * to the two ways to specify the argument values (see 'variant + * arguments'). If omitted, the variant is expected to always be + * available. + * - variant arguments: A list of arguments to pass to the variant callback. + * Variant arguments can be declared either as an associative array whose + * keys are the argument names or as an indexed array without specifying + * keys. If declared as an associative array, the arguments get passed to + * the variant callback as a single $options parameter whose keys are the + * argument names (i.e. $options is identical to the specified array). If + * declared as an indexed array, the array values get passed to the + * variant callback as separate arguments in the order they were declared. + * Variants can be version-specific (see 'versions'). + * - versions: (optional) An associative array of supported library versions. + * Naturally, libraries evolve over time and so do their APIs. In case a + * library changes between versions, different 'files' may need to be + * loaded, different 'variants' may become available, or Drupal modules need + * to load different integration files adapted to the new version. Each key + * is a version *string* (PHP does not support floats as keys). Each value + * is an associative array of top-level properties that are entirely + * overridden by the version. + * - integration files: (optional) An associative array whose keys are module + * names and whose values are sets of files to load for the module, using + * the same notion as the top-level 'files' property. Each specified file + * should contain the path to the file relative to the module it belongs to. + * - callbacks: An associative array whose keys are callback groups and whose + * values are arrays of callbacks to apply to the library in that group. + * Each callback receives the following arguments: + * - $library: An array of library information belonging to the top-level + * library, a specific version, a specific variant or a specific variant + * of a specific version. Because library information such as the 'files' + * property (see above) can be declared in all these different locations + * of the library array, but a callback may have to act on all these + * different parts of the library, it is called recursively for each + * library with a certain part of the libraries array passed as $library + * each time. + * - $version: If the $library array belongs to a certain version (see + * above), a string containing the version. This argument may be empty, so + * NULL should be specified as the default value. + * - $variant: If the $library array belongs to a certain variant (see + * above), a string containing the variant name. This argument may be + * empty, so NULL should be specified as the default value. + * Valid callback groups are: + * - info: Callbacks registered in this group are applied after the library + * information has been retrieved via hook_libraries_info() or info files. + * - pre-detect: Callbacks registered in this group are applied after the + * library path has been determined and before the version callback is + * invoked. At this point the following additional information is available: + * - $library['library path']: The path on the file system to the library. + * - post-detect: Callbacks registered in this group are applied after the + * library has been successfully detected. At this point the library + * contains the version-specific information, if specified, and following + * additional information is available: + * - $library['installed']: A boolean indicating whether the library is + * installed or not. + * - $library['version']: If it could be detected, a string containing the + * version of the library. + * - $library['variants'][$variant]['installed']: For each specified + * variant, a boolean indicating whether the variant is installed or + * not. + * Note that in this group the 'versions' property is no longer available. + * - pre-load: Callbacks registered in this group are applied directly + * before this library is loaded. At this point the library contains + * variant-specific information, if specified. Note that in this group the + * 'variants' property is no longer available. + * - post-load: Callbacks registered in this group are applied directly + * after this library is loaded. At this point, the library contains a + * 'loaded' key, which contains the number of files that were loaded. + * Additional top-level properties can be registered as needed. + * + * @see hook_library() + * + * @deprecated Will be removed before a stable Drupal 8 release. + */ +function hook_libraries_info() { + // The following is a full explanation of all properties. See below for more + // concrete example implementations. + + // This array key lets Libraries API search for 'sites/all/libraries/example' + // directory, which should contain the entire, original extracted library. + $libraries['example'] = array( + // Only used in administrative UI of Libraries API. + 'name' => 'Example library', + 'vendor url' => 'http://example.com', + 'download url' => 'http://example.com/download', + // Optional: If, after extraction, the actual library files are contained in + // 'sites/all/libraries/example/lib', specify the relative path here. + 'path' => 'lib', + // Optional: Define a custom version detection callback, if required. + 'version callback' => 'mymodule_get_version', + // Specify arguments for the version callback. By default, + // libraries_get_version() takes a named argument array: + 'version arguments' => array( + 'file' => 'docs/CHANGELOG.txt', + 'pattern' => '@version\s+([0-9a-zA-Z\.-]+)@', + 'lines' => 5, + 'cols' => 20, + ), + // Default list of files of the library to load. Important: Only specify + // third-party files belonging to the library here, not integration files of + // your module. + 'files' => array( + // 'js' and 'css' follow the syntax of hook_library(), but file paths are + // relative to the library path. + 'js' => array( + 'exlib.js', + 'gadgets/foo.js', + ), + 'css' => array( + 'lib_style.css', + 'skin/example.css', + ), + // For PHP libraries, specify include files here, still relative to the + // library path. + 'php' => array( + 'exlib.php', + 'exlib.inc', + ), + ), + // Optional: Specify alternative variants of the library, if available. + 'variants' => array( + // All properties defined for 'minified' override top-level properties. + 'minified' => array( + 'files' => array( + 'js' => array( + 'exlib.min.js', + 'gadgets/foo.min.js', + ), + 'css' => array( + 'lib_style.css', + 'skin/example.css', + ), + ), + 'variant callback' => 'mymodule_check_variant', + 'variant arguments' => array( + 'variant' => 'minified', + ), + ), + ), + // Optional, but usually required: Override top-level properties for later + // versions of the library. The properties of the minimum version that is + // matched override the top-level properties. Note: + // - When registering 'versions', it usually does not make sense to register + // 'files', 'variants', and 'integration files' on the top-level, as most + // of those likely need to be different per version and there are no + // defaults. + // - The array keys have to be strings, as PHP does not support floats for + // array keys. + 'versions' => array( + '2' => array( + 'files' => array( + 'js' => array('exlib.js'), + 'css' => array('exlib_style.css'), + ), + ), + '3.0' => array( + 'files' => array( + 'js' => array('exlib.js'), + 'css' => array('lib_style.css'), + ), + ), + '3.2' => array( + 'files' => array( + 'js' => array( + 'exlib.js', + 'gadgets/foo.js', + ), + 'css' => array( + 'lib_style.css', + 'skin/example.css', + ), + ), + ), + ), + // Optional: Register files to auto-load for your module. All files must be + // keyed by module, and follow the syntax of the 'files' property. + 'integration files' => array( + 'mymodule' => array( + 'js' => array('ex_lib.inc'), + ), + ), + // Optionally register callbacks to apply to the library during different + // stages of its lifetime ('callback groups'). + 'callbacks' => array( + // Used to alter the info associated with the library. + 'info' => array( + 'mymodule_example_libraries_info_callback', + ), + // Called before detecting the given library. + 'pre-detect' => array( + 'mymodule_example_libraries_predetect_callback', + ), + // Called after detecting the library. + 'post-detect' => array( + 'mymodule_example_libraries_postdetect_callback', + ), + // Called before the library is loaded. + 'pre-load' => array( + 'mymodule_example_libraries_preload_callback', + ), + // Called after the library is loaded. + 'post-load' => array( + 'mymodule_example_libraries_postload_callback', + ), + ), + ); + + // A very simple library. No changing APIs (hence, no versions), no variants. + // Expected to be extracted into 'sites/all/libraries/simple'. + $libraries['simple'] = array( + 'name' => 'Simple library', + 'vendor url' => 'http://example.com/simple', + 'download url' => 'http://example.com/simple', + 'version arguments' => array( + 'file' => 'readme.txt', + // Best practice: Document the actual version strings for later reference. + // 1.x: Version 1.0 + 'pattern' => '/Version (\d+)/', + 'lines' => 5, + ), + 'files' => array( + 'js' => array('simple.js'), + ), + ); + + // A library that (naturally) evolves over time with API changes. + $libraries['tinymce'] = array( + 'name' => 'TinyMCE', + 'vendor url' => 'http://tinymce.moxiecode.com', + 'download url' => 'http://tinymce.moxiecode.com/download.php', + 'path' => 'jscripts/tiny_mce', + // The regular expression catches two parts (the major and the minor + // version), which libraries_get_version() doesn't allow. + 'version callback' => 'tinymce_get_version', + 'version arguments' => array( + // It can be easier to parse the first characters of a minified file + // instead of doing a multi-line pattern matching in a source file. See + // 'lines' and 'cols' below. + 'file' => 'jscripts/tiny_mce/tiny_mce.js', + // Best practice: Document the actual version strings for later reference. + // 2.x: this.majorVersion="2";this.minorVersion="1.3" + // 3.x: majorVersion:'3',minorVersion:'2.0.1' + 'pattern' => '@majorVersion[=:]["\'](\d).+?minorVersion[=:]["\']([\d\.]+)@', + 'lines' => 1, + 'cols' => 100, + ), + 'versions' => array( + '2.1' => array( + 'files' => array( + 'js' => array('tiny_mce.js'), + ), + 'variants' => array( + 'source' => array( + 'files' => array( + 'js' => array('tiny_mce_src.js'), + ), + ), + ), + 'integration files' => array( + 'wysiwyg' => array( + 'js' => array('editors/js/tinymce-2.js'), + 'css' => array('editors/js/tinymce-2.css'), + ), + ), + ), + // Definition used if 3.1 or above is detected. + '3.1' => array( + // Does not support JS aggregation. + 'files' => array( + 'js' => array( + 'tiny_mce.js' => array('preprocess' => FALSE), + ), + ), + 'variants' => array( + // New variant leveraging jQuery. Not stable yet; therefore not the + // default variant. + 'jquery' => array( + 'files' => array( + 'js' => array( + 'tiny_mce_jquery.js' => array('preprocess' => FALSE), + ), + ), + ), + 'source' => array( + 'files' => array( + 'js' => array( + 'tiny_mce_src.js' => array('preprocess' => FALSE), + ), + ), + ), + ), + 'integration files' => array( + 'wysiwyg' => array( + 'js' => array('editors/js/tinymce-3.js'), + 'css' => array('editors/js/tinymce-3.css'), + ), + ), + ), + ), + ); + return $libraries; +} + +/** + * Alter the library information before detection and caching takes place. + * + * The library definitions are passed by reference. A common use-case is adding + * a module's integration files to the library array, so that the files are + * loaded whenever the library is. As noted above, it is important to declare + * integration files inside of an array, whose key is the module name. + * + * @see hook_libraries_info() + * + * @deprecated Will be removed before a stable Drupal 8 release. + */ +function hook_libraries_info_alter(&$libraries) { + $files = array( + 'php' => array('example_module.php_spellchecker.inc'), + ); + $libraries['php_spellchecker']['integration files']['example_module'] = $files; +} + +/** + * Specify paths to look for library info files. + * + * Libraries API looks in the following directories for library info files by + * default: + * - libraries + * - profiles/$profile/libraries + * - sites/all/libraries + * - sites/$site/libraries + * This hook allows you to specify additional locations to look for library info + * files. This should only be used for modules that declare many libraries. + * Modules that only implement a few libraries should implement + * hook_libraries_info(). + * + * @return + * An array of paths. + * + * @deprecated Will be removed before a stable Drupal 8 release. + */ +function hook_libraries_info_file_paths() { + // Taken from the Libraries test module, which needs to specify the path to + // the test library. + return array(drupal_get_path('module', 'libraries_test') . '/example'); +}