jquery_ui.module 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @file
  4. * Provides the jQuery UI plug-in to other Drupal modules.
  5. *
  6. * This module doesn't do too much, but it is a central location for any other
  7. * modules that implement the JQuery UI library. It ensures that multiple
  8. * modules will all include the same library script just once on any given page.
  9. */
  10. /**
  11. * Path to jQuery UI library.
  12. *
  13. * During site installation, JQUERY_UI_PATH is the absolute path to the
  14. * jQuery UI library. At all other times JQUERY_UI_PATH is relative, and
  15. * safe for use in URLs.
  16. */
  17. if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install') {
  18. define('JQUERY_UI_PATH', dirname(__FILE__) . '/jquery.ui');
  19. }
  20. else {
  21. define('JQUERY_UI_PATH', drupal_get_path('module', 'jquery_ui') . '/jquery.ui');
  22. }
  23. /**
  24. * Add the specified jQuery UI library files to this page.
  25. *
  26. * The ui.core file is always included automatically, as well as the
  27. * effects.core file if any of the effects libraries are used.
  28. *
  29. * @param $files
  30. * An array of what additional files (other than UI core) should be loaded
  31. * on the page, or a string with a single file name.
  32. */
  33. function jquery_ui_add($files = array()) {
  34. static $loaded_files, $ui_core, $effects_core, $weight;
  35. $jquery_ui_path = JQUERY_UI_PATH . '/ui';
  36. $compression = variable_get('jquery_update_compression_type', 'mini');
  37. // Convert file to an array if it's not one already, to compensate for
  38. // lazy developers. ;)
  39. if (!is_array($files)) {
  40. $files = array($files);
  41. }
  42. if (!isset($weight)) {
  43. $weight = JS_LIBRARY + 5;
  44. }
  45. // If core hasn't been added yet, add it.
  46. if (!isset($ui_core)) {
  47. $ui_core = TRUE;
  48. jquery_ui_add(array('ui.core'));
  49. }
  50. // Loop through list of files to include and add them to the page.
  51. foreach ($files as $file) {
  52. // Any effects files require the effects core file.
  53. if (!isset($effects_core) && strpos($file, 'effects.') === 0) {
  54. $effects_core = TRUE;
  55. jquery_ui_add(array('effects.core'));
  56. }
  57. // Load other files.
  58. if (!isset($loaded_files[$file])) {
  59. switch ($compression) {
  60. case 'none':
  61. $file_path = "$file.js";
  62. break;
  63. case 'pack':
  64. $file_path = "packed/$file.packed.js";
  65. break;
  66. case 'mini':
  67. default:
  68. $file_path = "minified/$file.min.js";
  69. break;
  70. }
  71. $js_path = $jquery_ui_path . '/' . $file_path;
  72. drupal_add_js($js_path, array('weight' => $weight++));
  73. $loaded_files[$file] = $js_path;
  74. }
  75. }
  76. }
  77. /**
  78. * Return the version of jQuery UI installed.
  79. */
  80. function jquery_ui_get_version() {
  81. $version = 0;
  82. if (file_exists(JQUERY_UI_PATH . '/version.txt')) {
  83. $version = file_get_contents(JQUERY_UI_PATH . '/version.txt');
  84. }
  85. return $version;
  86. }