| 1 | <?php |
||
| 10 | class JavascriptEventsMinifier implements MinifierInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Minify javascript prefixes on html event attributes. |
||
| 14 | * |
||
| 15 | * @param \ArjanSchouten\HtmlMinifier\MinifyContext $context |
||
| 16 | * |
||
| 17 | * @return \ArjanSchouten\HtmlMinifier\MinifyContext |
||
| 18 | */ |
||
| 19 | 2 | public function process(MinifyContext $context) |
|
| 20 | { |
||
| 21 | 2 | $contents = preg_replace_callback( |
|
| 22 | '/'. |
||
| 23 | 2 | Constants::$htmlEventNamePrefix.Constants::ATTRIBUTE_NAME_REGEX.' # Match an on{attribute} |
|
| 24 | \s*=\s* # Match equals sign with optional whitespaces around it |
||
| 25 | ["\']? # Match an optional quote |
||
| 26 | \s*javascript: # Match the text "javascript:" which should be removed |
||
| 27 | /xis', |
||
| 28 | 2 | function ($match) { |
|
| 29 | 1 | return str_replace('javascript:', '', $match[0]); |
|
| 30 | 2 | }, $context->getContents()); |
|
| 31 | |||
| 32 | 2 | return $context->setContents($contents); |
|
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Indicates if minification rules depends on command options. |
||
| 37 | * |
||
| 38 | * @return string |
||
| 39 | */ |
||
| 40 | 3 | public function provides() |
|
| 44 | } |
||
| 45 |