Path: blob/master/src/applications/celerity/api.php
12249 views
<?php12/**3* Include a CSS or JS static resource by name. This function records a4* dependency for the current page, so when a response is generated it can be5* included. You can call this method from any context, and it is recommended6* you invoke it as close to the actual dependency as possible so that page7* dependencies are minimized.8*9* For more information, see @{article:Adding New CSS and JS}.10*11* @param string Name of the celerity module to include. This is whatever you12* annotated as "@provides" in the file.13* @return void14*/15function require_celerity_resource($symbol, $source_name = 'phabricator') {16$response = CelerityAPI::getStaticResourceResponse();17$response->requireResource($symbol, $source_name);18}192021/**22* Generate a node ID which is guaranteed to be unique for the current page,23* even across Ajax requests. You should use this method to generate IDs for24* nodes which require a uniqueness guarantee.25*26* @return string A string appropriate for use as an 'id' attribute on a DOM27* node. It is guaranteed to be unique for the current page, even28* if the current request is a subsequent Ajax request.29*/30function celerity_generate_unique_node_id() {31static $uniq = 0;32$response = CelerityAPI::getStaticResourceResponse();33$block = $response->getMetadataBlock();3435return 'UQ'.$block.'_'.($uniq++);36}373839/**40* Get the versioned URI for a raw resource, like an image.41*42* @param string Path to the raw image.43* @return string Versioned path to the image, if one is available.44*/45function celerity_get_resource_uri($resource, $source = 'phabricator') {46$resource = ltrim($resource, '/');4748$map = CelerityResourceMap::getNamedInstance($source);49$response = CelerityAPI::getStaticResourceResponse();50return $response->getURI($map, $resource);51}525354