pquery.js.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * pQuery plugin for parsing templates.
  4. *
  5. * @package pQuery
  6. */
  7. __p::require_plugins('cache');
  8. __p::load_utils('jshrink');
  9. /**
  10. * @todo Documentation
  11. */
  12. class pQueryJs extends pQueryCache {
  13. static $accepts = array('array' => 'add_extensions', 'string' => 'make_array');
  14. /**
  15. * Make a single file into an array.
  16. *
  17. * @param string $file The file to put in an array.
  18. */
  19. function make_array($file) {
  20. return $this->add_extensions(array($file));
  21. }
  22. /**
  23. *
  24. *
  25. * @param array $files
  26. */
  27. function add_extensions($files) {
  28. foreach( $files as $i => $file )
  29. if( !preg_match('/\.js$/', $file) )
  30. $files[$i] = $file.'.js';
  31. return $this->get_modification_dates($files);
  32. }
  33. /**
  34. *
  35. */
  36. function minify() {
  37. $this->content = trim(JShrink::minify($this->content, array('flaggedComments' => false)));
  38. return $this;
  39. }
  40. /**
  41. *
  42. */
  43. function set_headers() {
  44. header('Content-Type: application/javascript');
  45. return $this;
  46. }
  47. }
  48. /**
  49. * Shortcut constructor for {@link pQueryJs}.
  50. *
  51. * @param array|string $scripts
  52. * @returns pQueryJs A new script cache instance.
  53. */
  54. function _js($scripts) {
  55. return pQuery::create('js', $scripts);
  56. }
  57. /*
  58. * Add plugin to pQuery
  59. */
  60. __p::extend('pQueryJs', 'js');
  61. ?>