PluginProbe
Depicter — Popup & Slider Builder / 1.5.2
Depicter — Popup & Slider Builder v1.5.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Document / CSS / Selector.php

Selector.php in Depicter — Popup & Slider Builder 1.5.2, at app/src/Document/CSS/Selector.php

74 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Document\CSS;
3
4
5 use Averta\Core\Utility\Str;
6
7 class Selector
8 {
9 const PREFIX_NAME = 'depicter';
10 const PREFIX = 'depicter-';
11 const PREFIX_CSS = 'depicter-revert';
12
13 const DOCUMENT_PREFIX = 'document';
14 const SECTION_PREFIX = 'section';
15 const ELEMENT_PREFIX = 'element';
16
17 /**
18 * Retrieves raw selector path for a tag.
19 *
20 * @param int $documentId Document ID
21 * @param int|null $sectionId Section ID
22 * @param int|null $elementId Element ID
23 *
24 * @return string
25 */
26 public static function getSelectorPath( $documentId, $sectionId = null, $elementId = null )
27 {
28 $selectorPath = "{$documentId}";
29 if( $sectionId ){
30 $selectorPath .= "-" . self::SECTION_PREFIX . '-' . $sectionId;
31 }
32 if( $elementId ){
33 $selectorPath .= "-" . self::ELEMENT_PREFIX . '-' . $elementId;
34 }
35
36 return $selectorPath;
37 }
38
39 /**
40 * Retrieves selector path with prefix for a tag.
41 *
42 * @param int $documentId Document ID
43 * @param int|null $sectionId Section ID
44 * @param int|null $elementId Element ID
45 * @param string $typePrefix Target type ( document, section, element )
46 *
47 * @return string
48 */
49 public static function getFullSelectorPath( $documentId, $sectionId = null, $elementId = null, $typePrefix = '' )
50 {
51 return self::prefixify( $typePrefix ) . ( $typePrefix ? '-' : '' ) . self::getSelectorPath( $documentId, $sectionId, $elementId );
52 }
53
54 public static function getUniqueSelector( $documentId, $sectionId = null, $elementId = null, $typePrefix = '' )
55 {
56 // return self::getHashedSelector( self::getSelectorPath( $documentId, $sectionId, $elementId ), $typePrefix );
57 $sectionId = $typePrefix == 'element' ? null : $sectionId;
58 $elementId = $typePrefix == 'section' ? null : $elementId;
59
60 return self::getFullSelectorPath( $documentId, $sectionId, $elementId );
61 }
62
63 public static function getHashedSelector( $selector, $typePrefix = '' )
64 {
65 return self::prefixify( $typePrefix ) . ( $typePrefix ? '-' : '' ) . Str::shortHash( $selector );
66 }
67
68 public static function prefixify( $string = '' )
69 {
70 return self::PREFIX . $string;
71 }
72
73 }
74