@@ -3,6 +3,11 @@ function initManageSegmentsPage() {
33 if ( ! root ) {
44 return ;
55 }
6+ const panelApi = window . matomoPluginSegmentEditor
7+ && window . matomoPluginSegmentEditor . panelAPI ;
8+ if ( ! panelApi ) {
9+ return ;
10+ }
611 const tbody = root . querySelector ( 'tbody' ) ;
712 const rowList = Array . from ( tbody . children ) . reverse ( ) ;
813 const noResultElement = root . querySelector ( '.tableFooterLabel' ) ;
@@ -14,7 +19,7 @@ function initManageSegmentsPage() {
1419 initListener ( ) ;
1520 initHref ( ) ;
1621 initTitles ( ) ;
17- window . SegmentEditorPanel . onSegmentsStarChange ( onSegmentsStarChange ) ;
22+ panelApi . onSegmentsStarChange ( onSegmentsStarChange ) ;
1823 }
1924
2025 function reorderSegments ( ) {
@@ -49,7 +54,8 @@ function initManageSegmentsPage() {
4954 rowList . forEach ( function ( row ) {
5055 const definition = row . getAttribute ( 'data-segment-definition' ) ;
5156 const $dashboardLink = $ ( '.icon-show' , row ) ;
52- $dashboardLink . attr ( 'href' , window . broadcast . buildReportingUrl ( 'category=Dashboard_Dashboard&segment=' + definition ) ) ;
57+ const encodedDefinition = encodeURIComponent ( definition || '' ) ;
58+ $dashboardLink . attr ( 'href' , window . broadcast . buildReportingUrl ( `category=Dashboard_Dashboard&segment=${ encodedDefinition } ` ) ) ;
5359 } ) ;
5460 }
5561
@@ -59,19 +65,19 @@ function initManageSegmentsPage() {
5965 const $editButton = $ ( '[data-edit-segment]' , row ) ;
6066 const $deleteButton = $ ( '[data-delete-segment]' , row ) ;
6167 const idSegment = $starButton . attr ( 'data-star' ) ;
62- const segment = window . SegmentEditorPanel . getSegmentFromId ( idSegment ) ;
68+ const segment = panelApi . getSegmentFromId ( idSegment ) ;
6369 if ( segment && typeof segment . enable_only_idsite === 'string' ) {
6470 segment . enable_only_idsite = parseInt ( segment . enable_only_idsite , 10 ) || 0 ;
6571 }
66- const canEdit = window . SegmentEditorPanel . getCanUserEditSegment ( segment ) ;
72+ const canEdit = panelApi . getCanUserEditSegment ( segment ) ;
6773 if ( ! canEdit ) {
6874 $starButton . attr ( 'data-state' , 'disabled' ) ;
6975 $editButton . attr ( 'data-state' , 'disabled' ) ;
7076 $deleteButton . attr ( 'data-state' , 'disabled' ) ;
7177 }
72- window . SegmentEditorPanel . updateStarSegmentTitle ( $starButton , segment ) ;
73- $editButton . attr ( 'title' , window . SegmentEditorPanel . getEditSegmentTitle ( segment , canEdit ) ) ;
74- $deleteButton . attr ( 'title' , window . SegmentEditorPanel . getDeleteSegmentTitle ( segment , canEdit ) ) ;
78+ panelApi . updateStarSegmentTitle ( $starButton , segment ) ;
79+ $editButton . attr ( 'title' , panelApi . getEditSegmentTitle ( segment , canEdit ) ) ;
80+ $deleteButton . attr ( 'title' , panelApi . getDeleteSegmentTitle ( segment , canEdit ) ) ;
7581 } ) ;
7682 }
7783
@@ -84,7 +90,7 @@ function initManageSegmentsPage() {
8490 return false ;
8591 }
8692 const idSegment = $button . attr ( 'data-edit-segment' ) ;
87- SegmentEditorPanel . openEditFormGivenIdSegment ( idSegment ) ;
93+ panelApi . openEditFormGivenIdSegment ( idSegment ) ;
8894 } ) ;
8995 $ ( root ) . on ( 'click' , '[data-delete-segment]' , function ( e ) {
9096 e . stopPropagation ( ) ;
@@ -94,8 +100,8 @@ function initManageSegmentsPage() {
94100 return false ;
95101 }
96102 const idSegment = $button . attr ( 'data-delete-segment' ) ;
97- SegmentEditorPanel . openEditFormGivenIdSegment ( idSegment ) ;
98- SegmentEditorPanel . askToDeleteSegment ( idSegment ) ;
103+ panelApi . openEditFormGivenIdSegment ( idSegment ) ;
104+ panelApi . askToDeleteSegment ( idSegment ) ;
99105 } ) ;
100106 $ ( root ) . on ( 'click' , '[data-star]' , function ( e ) {
101107 e . stopPropagation ( ) ;
@@ -106,7 +112,7 @@ function initManageSegmentsPage() {
106112 }
107113 const $segment = $button . closest ( 'tr' ) ;
108114 const idSegment = $button . attr ( 'data-star' ) ;
109- window . SegmentEditorPanel . toggleStarredSegment ( $segment , idSegment ) ;
115+ panelApi . toggleStarredSegment ( $segment , idSegment ) ;
110116 } ) ;
111117 $ ( root ) . on ( 'input' , '#manageSegmentSearch' , function ( e ) {
112118 e . stopPropagation ( ) ;
@@ -128,7 +134,7 @@ function initManageSegmentsPage() {
128134 $ ( root ) . on ( 'click' , '.createNewSegment' , function ( e ) {
129135 e . stopPropagation ( ) ;
130136 e . preventDefault ( ) ;
131- window . SegmentEditorPanel . openEditFormGivenIdSegment ( ) ;
137+ panelApi . openEditFormGivenIdSegment ( ) ;
132138 } ) ;
133139 }
134140
@@ -144,20 +150,20 @@ function initManageSegmentsPage() {
144150 if ( tooltip ) {
145151 tooltip . disable ( ) ;
146152 }
147- window . SegmentEditorPanel . updateStarSegmentTitle ( $starButton , segment ) ;
153+ panelApi . updateStarSegmentTitle ( $starButton , segment ) ;
148154 if ( tooltip ) {
149155 tooltip . enable ( ) ;
150156 }
151157 $segment . attr ( 'data-segment-order' , $previousOrder === '2' ? 2 : segment . starred ? 1 : 0 ) ;
152158 reorderSegments ( ) ;
153- window . SegmentEditorPanel . triggerStarAnimation ( $segment , segment , isError ) ;
159+ panelApi . triggerStarAnimation ( $segment , segment , isError ) ;
154160 }
155161
156162 function filterSegmentList ( keyword ) {
157163 clearFilterSegmentList ( ) ;
158- const search = window . SegmentEditorPanel . normalizeSearchString ( keyword ) ;
164+ const search = panelApi . normalizeSearchString ( keyword ) ;
159165 rowList . forEach ( function ( row ) {
160- const segmentSeed = window . SegmentEditorPanel . normalizeSearchString ( $ ( row ) . attr ( 'data-segment-name' ) ) ;
166+ const segmentSeed = panelApi . normalizeSearchString ( $ ( row ) . attr ( 'data-segment-name' ) ) ;
161167 if ( segmentSeed . indexOf ( search ) === - 1 ) {
162168 $ ( row ) . hide ( ) ;
163169 }
0 commit comments