respondjs.module 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @file
  4. * Main file for the Respond.js module
  5. */
  6. define('RESPONDJS_DOWNLOAD_URI', 'https://raw.githubusercontent.com/scottjehl/Respond/master/dest/respond.min.js');
  7. define('RESPONDJS_DOWNLOAD_LOCATION', 'sites/all/libraries/respondjs');
  8. define('RESPONDJS_SCOPE_DEFAULT','header');
  9. define('RESPONDJS_QUIET_DEFAULT',NULL);
  10. /**
  11. * Implements hook_menu().
  12. *
  13. * Provides admin config pages.
  14. */
  15. function respondjs_menu() {
  16. $items = array();
  17. $items['admin/config/media/respondjs'] = array(
  18. 'title' => 'Respond.js',
  19. 'description' => 'Configure respond.js settings',
  20. 'page callback' => 'drupal_get_form',
  21. 'page arguments' => array('respondjs_admin'),
  22. 'access arguments' => array('administer respondjs'),
  23. 'file' => 'respondjs.admin.inc',
  24. 'type' => MENU_NORMAL_ITEM,
  25. );
  26. return $items;
  27. }
  28. /**
  29. * Implements hook_permission().
  30. */
  31. function respondjs_permission() {
  32. return array(
  33. 'administer respondjs' => array(
  34. 'title' => t('Administer respond.js'),
  35. ),
  36. );
  37. }
  38. /**
  39. * Implements hook_page_build().
  40. *
  41. * This is the function that adds respond.js to the page.
  42. */
  43. function respondjs_page_build() {
  44. // We need respond.js to load as soon in the HTML as possible, because it can
  45. // affect the presentation of a page. The options below ensure that it happens.
  46. drupal_add_js(
  47. respondjs_get_library_file(),
  48. array(
  49. 'type' => 'file',
  50. 'scope' => variable_get('respondjs_scope', RESPONDJS_SCOPE_DEFAULT),
  51. 'group' => JS_LIBRARY,
  52. 'every_page' => TRUE,
  53. 'weight' => -999,
  54. 'preprocess' => 0,
  55. )
  56. );
  57. }
  58. /**
  59. * Implements hook_library().
  60. */
  61. function respondjs_library() {
  62. $libraries['respondjs'] = array(
  63. 'title' => 'Respond.js',
  64. 'website' => 'https://github.com/scottjehl/Respond',
  65. 'version' => '',
  66. 'js' => array(
  67. respondjs_get_library_file() => array(),
  68. ),
  69. );
  70. return $libraries;
  71. }
  72. /**
  73. * Helper function gets the path to the library directory
  74. */
  75. function respondjs_get_library_path() {
  76. $default_path = drupal_get_path('module', 'respondjs') . '/lib';
  77. // If Libraries API is enabled, make sure the file exists before pointing there
  78. if (function_exists('libraries_get_path') && file_exists(libraries_get_path('respondjs'))) {
  79. $path = libraries_get_path('respondjs');
  80. }
  81. // Respond.js is GPLv2 so we can ship it in the module folder as a fallback.
  82. // However, we still check to be on the safe side.
  83. else if (file_exists($default_path)) {
  84. $path = $default_path;
  85. }
  86. // If the module's files have been altered, we should not report the default path.
  87. // repsondjs_requirements() will report this error.
  88. else {
  89. $path = NULL;
  90. }
  91. return $path;
  92. }
  93. /**
  94. * Helper function gets the path to the library Javascript file
  95. */
  96. function respondjs_get_library_file() {
  97. return respondjs_get_library_path() . '/respond.min.js';
  98. }