Source of file SilverStripeJquery.php
Size: 2,291 Bytes - Last Modified: 2021-12-24T06:49:05+00:00
/var/www/docs.ssmods.com/process/src/code/helpers/SilverStripeJquery.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 | <?php class SilverStripeJquery { /** * * @var ReflectionProperty */ private $requirementsJSProp; /** * * @var Requirements */ protected $backend; public static function create() { return new static(); } public function __construct() { $this->backend = Requirements::backend(); } public static function requireJquery() { return static::create()->mungeRequirementsJs(static::getFrameworkJqueryFiles(), static::getRequirementFiles()); } protected function mungeRequirementsJs($toBlock, $toPrepend) { foreach ($toBlock as $block) { Requirements::block($block); } $prependJs = array(); foreach ($toPrepend as $prepend) { $prependJs[$prepend] = true; } $this->setRequirementsJS(array_merge($prependJs, $this->getRequirementsJS())); return $this; } /** * * @return ReflectionProperty */ protected function getRequirementsJSProp() { if (!$this->requirementsJSProp) { $class = new ReflectionClass($this->backend); $this->requirementsJSProp = $class->getProperty("javascript"); $this->requirementsJSProp->setAccessible(true); } return $this->requirementsJSProp; } /** * * @return ReflectionProperty */ protected function getRequirementsJS() { return $this->getRequirementsJSProp()->getValue($this->backend); } /** * * @return ReflectionProperty */ protected function setRequirementsJS($requirementsJs) { return $this->getRequirementsJSProp()->setValue($this->backend, $requirementsJs); } public static function getRequirementFiles() { $jsMin = (Director::isDev()) ? "" : ".min"; return array( SS_JQUERY_DIR."/thirdparty/jquery/jquery".$jsMin.".js", SS_JQUERY_DIR."/thirdparty/jquery-migrate/jquery-migrate".$jsMin.".js" ); } public static function getFrameworkJqueryFiles() { return array( FRAMEWORK_DIR."/thirdparty/jquery/jquery.js", FRAMEWORK_DIR."/thirdparty/jquery/jquery.min.js" ); } } |