Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/celerity/api.php
12249 views
1
<?php
2
3
/**
4
* Include a CSS or JS static resource by name. This function records a
5
* dependency for the current page, so when a response is generated it can be
6
* included. You can call this method from any context, and it is recommended
7
* you invoke it as close to the actual dependency as possible so that page
8
* dependencies are minimized.
9
*
10
* For more information, see @{article:Adding New CSS and JS}.
11
*
12
* @param string Name of the celerity module to include. This is whatever you
13
* annotated as "@provides" in the file.
14
* @return void
15
*/
16
function require_celerity_resource($symbol, $source_name = 'phabricator') {
17
$response = CelerityAPI::getStaticResourceResponse();
18
$response->requireResource($symbol, $source_name);
19
}
20
21
22
/**
23
* Generate a node ID which is guaranteed to be unique for the current page,
24
* even across Ajax requests. You should use this method to generate IDs for
25
* nodes which require a uniqueness guarantee.
26
*
27
* @return string A string appropriate for use as an 'id' attribute on a DOM
28
* node. It is guaranteed to be unique for the current page, even
29
* if the current request is a subsequent Ajax request.
30
*/
31
function celerity_generate_unique_node_id() {
32
static $uniq = 0;
33
$response = CelerityAPI::getStaticResourceResponse();
34
$block = $response->getMetadataBlock();
35
36
return 'UQ'.$block.'_'.($uniq++);
37
}
38
39
40
/**
41
* Get the versioned URI for a raw resource, like an image.
42
*
43
* @param string Path to the raw image.
44
* @return string Versioned path to the image, if one is available.
45
*/
46
function celerity_get_resource_uri($resource, $source = 'phabricator') {
47
$resource = ltrim($resource, '/');
48
49
$map = CelerityResourceMap::getNamedInstance($source);
50
$response = CelerityAPI::getStaticResourceResponse();
51
return $response->getURI($map, $resource);
52
}
53
54