Skip to content

Commit 92a15a7

Browse files
committed
Add tooltip on stars and fix existing tooltips
1 parent 5eb059e commit 92a15a7

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

lang/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"Action": "Action",
99
"Actions": "Actions",
1010
"Add": "Add",
11+
"AddToFavorites": "Add to favorites",
1112
"AfterEntry": "after entering here",
1213
"All": "All",
1314
"AllWebsitesDashboard": "All Websites dashboard",
@@ -418,6 +419,7 @@
418419
"RelatedReport": "Related report",
419420
"RelatedReports": "Related reports",
420421
"Remove": "Remove",
422+
"RemoveFromFavorites": "Remove from favorites",
421423
"Report": "Report",
422424
"ReportGeneratedFrom": "This report was generated using data from %s.",
423425
"ReportRatioTooltip": "'%1$s' represents %2$s of %3$s %4$s in segment %5$s with %6$s.",

plugins/SegmentEditor/SegmentSelectorControl.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ private function getTranslations()
127127
'General_DefaultAppended',
128128
'SegmentEditor_AddNewSegment',
129129
'General_Edit',
130+
'General_AddToFavorites',
131+
'General_RemoveFromFavorites',
132+
'General_Edit',
130133
'General_Search',
131134
'General_SearchNoResults',
132135
);

plugins/SegmentEditor/javascripts/Segmentation.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,9 @@ Segmentation = (function($) {
7575
};
7676

7777
segmentation.prototype.setTooltip = function (segmentDescription) {
78-
79-
var title = _pk_translate('SegmentEditor_ChooseASegment') + '.';
80-
title += ' '+ _pk_translate('SegmentEditor_CurrentlySelectedSegment', [segmentDescription]);
81-
82-
$('a.title', this.content).attr('title', title).tooltip({
83-
track: true,
84-
show: {delay: 700, duration: 200}, // default from Tooltips.js
85-
hide: false,
86-
content: title,
87-
});
78+
var title = _pk_translate('SegmentEditor_ChooseASegment') + '.';
79+
title += ' '+ _pk_translate('SegmentEditor_CurrentlySelectedSegment', [segmentDescription]);
80+
addTooltip($('a.title', this.content), title);
8881
};
8982

9083
segmentation.prototype.markComparedSegments = function() {
@@ -186,7 +179,7 @@ Segmentation = (function($) {
186179
var isSharedWithMeBySuperUserNoticeAlreadyDisplayedOnce = false;
187180
var isSharedWithMeBySuperUserNoticeShouldBeClosed = false;
188181

189-
if(self.availableSegments.length > 0) {
182+
if (self.availableSegments.length > 0) {
190183

191184
for(var i = 0; i < self.availableSegments.length; i++)
192185
{
@@ -225,12 +218,11 @@ Segmentation = (function($) {
225218
'<li class="' + injClass.join(' ') + '"' +
226219
'data-idsegment="' + segment.idsegment + '"' +
227220
'data-definition="' + escapedSegmentName + '"' +
228-
'title="' + getSegmentTooltipEnrichedWithUsername(segment) + '"' +
229221
'>' +
230-
'<span class="segname" tabindex="4">' + getSegmentName(segment) + '</span>';
222+
'<span class="segname" tabindex="4" title="' + getSegmentTooltipEnrichedWithUsername(segment) + '" >' + getSegmentName(segment) + '</span>';
231223
if (self.segmentAccess === "write") {
232224
listHtml += '' +
233-
'<button data-star class="starSegment">️' +
225+
'<button data-star class="starSegment" title="' + self.translations[segment.starred ? 'General_RemoveFromFavorites' : 'General_AddToFavorites'].toLocaleLowerCase() + '">️' +
234226
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24">' +
235227
'<path stroke="black" stroke-width="3" fill="none" d="M9.153 5.408C10.42 3.136 11.053 2 12 2c.947 0 1.58 1.136 2.847 3.408l.328.588c.36.646.54.969.82 1.182.28.213.63.292 1.33.45l.636.144c2.46.557 3.689.835 3.982 1.776.292.94-.546 1.921-2.223 3.882l-.434.507c-.476.557-.715.836-.822 1.18-.107.345-.071.717.001 1.46l.066.677c.253 2.617.38 3.925-.386 4.506-.766.582-1.918.051-4.22-1.009l-.597-.274c-.654-.302-.981-.452-1.328-.452-.347 0-.674.15-1.329.452l-.595.274c-2.303 1.06-3.455 1.59-4.22 1.01-.767-.582-.64-1.89-.387-4.507l.066-.676c.072-.744.108-1.116 0-1.46-.106-.345-.345-.624-.821-1.18l-.434-.508c-1.677-1.96-2.515-2.941-2.223-3.882.293-.941 1.523-1.22 3.983-1.776l.636-.144c.699-.158 1.048-.237 1.329-.45.28-.213.46-.536.82-1.182l.328-.588Z"/>' +
236228
'</svg>' +
@@ -423,9 +415,12 @@ Segmentation = (function($) {
423415
e.stopPropagation();
424416
e.preventDefault();
425417
const $root = $(this).closest('li');
418+
const $starButton = $root.find('.starSegment');
426419
const idSegment = $root.data('idsegment');
427420
const segment = getSegmentFromId(idSegment);
428421
segment.starred = !segment.starred;
422+
const title = self.translations[segment.starred ? 'General_RemoveFromFavorites' : 'General_AddToFavorites'].toLocaleLowerCase();
423+
addTooltip($starButton, title);
429424
const method = segment.starred ? 'star' : 'unstar';
430425
$root.toggleClass('segmentStarred', segment.starred);
431426

@@ -595,11 +590,13 @@ Segmentation = (function($) {
595590

596591
};
597592

598-
var getAddOrBlockButtonHtml = function(){
599-
if(typeof addOrBlockButton === "undefined") {
600-
var addOrBlockButton = self.editorTemplate.find("div.segment-add-or").clone();
601-
}
602-
return addOrBlockButton.clone();
593+
function addTooltip(element, title) {
594+
$(element).attr('title', title).tooltip({
595+
track: true,
596+
show: { delay: 700, duration: 200 }, // default from Tooltips.js
597+
hide: false,
598+
content: title,
599+
});
603600
};
604601

605602
function openEditFormGivenSegment(option) {
@@ -897,6 +894,10 @@ Segmentation = (function($) {
897894
// Loading message
898895
var segmentIsSet = this.getSegment().length;
899896
toggleLoadingMessage(segmentIsSet);
897+
898+
self.target.find('[title]').each(function () {
899+
addTooltip(this, this.getAttribute('title'));
900+
});
900901
};
901902

902903
if (piwikHelper.isReportingPage()) {

0 commit comments

Comments
 (0)